Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:09:56+00:00 2026-06-11T22:09:56+00:00

I’ve started work with boost:icl library which is really comprehensive and convenient. I’m using

  • 0

I’ve started work with boost:icl library which is really comprehensive and convenient. I’m using mostly two types of intervals from boost, boost::icl::interval_set and boost::icl::interval_map. Some times I have to manipulate with just interval part of both types, and I don’t interesting in doing replicate functions.

So here is my example:

template<typename T>
void UniqSegmentsInA(T &a,T &b,T &c,int max_gap=200)
{
typename T::iterator __it1 = a.begin();
typename T::iterator __it2 = b.begin();
bool _checking_=true;

while(__it1 != a.end() && __it2 != b.end())
{
    typename T::interval_type __itv1  = getFirst(*__it1);
    typename T::interval_type __itv2  = getFirst(*__it2);

    if(__itv1.upper()>__itv2.upper())
    {
        /*if segments intersect and we should move second segment then segment A should not be included in output*/
        if(intersects(T::interval_type::closed(__itv1.lower()-max_gap,__itv1.upper()+max_gap),__itv2)) _checking_=false;
        __it2++;
    }
    else
    {
        if(!intersects(T::interval_type::closed(__itv1.lower()-max_gap,__itv1.upper()+max_gap),__itv2) && _checking_)
        {
            c.add((*__it1));
        }
        _checking_=true;
        __it1++;
    }
}
if(__it1 != a.end() && !_checking_) __it1++;
while(__it1 != a.end())
{
    c.add(*__it1);
    __it1++;
}
}

getFirst() is a helper function when it is a map then it returns .first when it is a set then just an iterator.

bicl::interval_map<int,int>::interval_type inline getFirst(bicl::interval_map<int,int>::segment_type a)
{
return a.first;
}

bicl::interval_set<int>::interval_type inline getFirst(bicl::interval_set<int>::segment_type a)
{
return a;
}

So this example works like expected. What I want to improve is getFirst() function and I don’t want hardcode types of domain and codomain in interval_map/set. I’ve tried something like this:

template<typename T>
typename bicl::interval_map<T,T>::interval_type inline getFirst(typename bicl::interval_map<T,T>::segment_type a)
{
return a.first;
}

Then I changed:

    typename T::interval_type __itv1  = getFirst<typename T::domain_type>(*__it1);
    typename T::interval_type __itv2  = getFirst<typename T::domain_type>(*__it2);

but it does not work and compiler gives an error:

src/Intersections.cpp:324:35: error: no matching function for call to ‘getFirst(const std::pair<const boost::icl::discrete_interval<int, std::less>, int>&)’
src/Intersections.cpp:324:35: note: candidates are:
src/Intersections.cpp:52:56: note: template<class T> typename boost::icl::interval_map<T, T>::interval_type getFirst(typename boost::icl::interval_map<T, T>::segment_type)
src/Intersections.cpp:57:56: note: boost::icl::interval_set<int>::interval_type getFirst(boost::icl::interval_set<int>::segment_type)
src/Intersections.cpp:57:56: note:   no known conversion for argument 1 from ‘const std::pair<const boost::icl::discrete_interval<int, std::less>, int>’ to ‘boost::icl::interval_set<int>::segment_type {aka boost::icl::discrete_interval<int, std::less>}’

So question is, is it possible in this example do not hardcode domain and codomain types in getFirst() function?

Thanks,
Andrey

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:09:57+00:00Added an answer on June 11, 2026 at 10:09 pm

    You can use the function template

    key_value
    

    for that purpose. It is defined in

    boost\icl\concept\set_value.hpp
    and
    boost\icl\concept\map_value.hpp
    

    like this

    template<class Type, class Iterator>
    inline typename enable_if<is_set<Type>, const typename Type::key_type>::type&
    key_value(Iterator it_)
    {
        return *it_;
    }
    
    template<class Type, class Iterator>
    inline typename enable_if<is_map<Type>, const typename Type::key_type>::type&
    key_value(Iterator it_)
    {
        return (*it_).first;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.