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

  • SEARCH
  • Home
  • 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 7690631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:26:30+00:00 2026-05-31T20:26:30+00:00

Traditional task of iterating trough key set of std::map led me to another mess

  • 0

Traditional task of iterating trough key set of std::map led me to another mess which seems not to be disscused here yet.

In short, this code does not compile (C++11 is heavily used):

typedef std::pair<int, int> Pair;
vector<Pair> v {Pair(1,2), Pair(2,3)};
using namespace std::placeholders;
auto choose_first = std::bind(&Pair::first, _1);
boost::make_transform_iterator(v.begin(), choose_first);

Error message is as follows.

no type named 'result_type' in 'struct std::_Bind<std::_Mem_fn<int std::pair<int, int>::*>(std::_Placeholder<1>)>' 

At the same time, changing std::bind to boost::bind fixes the problem. But there is a code convention in my project that we use std::bind only.

Any suggestions what to do with this? (Should I write bugreport to the Boost team?)

  • 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-05-31T20:26:31+00:00Added an answer on May 31, 2026 at 8:26 pm

    There are better ways to iterate over the keys of a std::map (or any container whose value_type is pair<T,U>), namely Boost.Range‘s map_keys adaptor (there’s also a map_values one):

    #include <boost/range/adaptor/map.hpp>
    #include <utility>
    #include <vector>
    #include <iostream>
    
    int main(){
      typedef std::pair<int, int> Pair;
      std::vector<Pair> v {Pair(1,2), Pair(2,3)};
      for(auto& first : v | boost::adaptors::map_keys){
        std::cout << first << " ";
      }
    }
    

    But back to your problem: All Boost libraries use the Boost.Utility function result_of, which won’t fall back to std::result_of for whatever reason, and also won’t use decltype if it’s available without you telling it to. You do so by putting #define BOOST_RESULT_OF_USE_DECLTYPE before the first Boost include.

    That, however, still didn’t make your code compile with Clang 3.1 SVN + libc++. Here’s the code I used:

    #define BOOST_RESULT_OF_USE_DECLTYPE
    #include <boost/iterator/transform_iterator.hpp>
    #include <utility>
    #include <vector>
    #include <functional>
    
    int main(){
      typedef std::pair<int, int> Pair;
      std::vector<Pair> v {Pair(1,2), Pair(2,3)};
      using namespace std::placeholders;
      auto choose_first = std::bind(&Pair::first, _1);
      boost::make_transform_iterator(v.begin(), choose_first);
    }
    

    Compiled with:

    clang++ -std=c++0x -stdlib=libc++ -Wall -pedantic -Ipath/to/boost -Wno-mismatched-tags t.cpp
    

    GCC 4.7 seems to accept this just fine, so I guess it’s a bug in libc++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple slightly modified / non-traditional setups for feedforward neural networks which
I have a traditional web site which serves users from desktop computer browsers. I
By the traditional way I mean registering the DLL in registry. There seems to
I have a program which runs a certain processing suits on a large set
Traditional wisdom says not to call into child namespaces from a parent. Let's say
Suppose I've 3 prj sites which is used to maintain a prj task Prj
I have a asp.net application which is written in the traditional method [SqlConnection. SqlAdapter..
In traditional ASP.NET (Web Forms), the UpdatePanel control lets you do a partial refresh
A traditional C++ class (just some random declarations) might resemble the following: class Foo
I have a traditional ASP.NET GridView. Inside of it I have a Template Field

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.