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 7656241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:42:58+00:00 2026-05-31T12:42:58+00:00

I have the following code: int MimeDocument::GetAttachmentId( std::string const& content_id ) { using namespace

  • 0

I have the following code:

int MimeDocument::GetAttachmentId( std::string const& content_id )
{
    using namespace boost::lambda;
    using boost::lambda::_1;
    using boost::bind;

    int id = 0;

    std::vector<std::string>::iterator it =
        std::find_if( attachment_list_.begin(), attachment_list_.end(),
            bind( &std::string::find, content_id, _1 ) != std::string::npos
        );

    if( it != attachment_list_.end() ) {
        id = std::distance( attachment_list_.begin(), it );
    }

    return id;
}

Which when compiled on MSVC9 SP1 results in tons of C2780 compiler errors. Here are just a few from the top of the list:

1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(210) : error C2780: 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided
1>        c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\bind\bind.hpp(1728) : see declaration of 'boost::bind'
1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(210) : error C2780: 'boost::_bi::bind_t<Rt2,boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,_bi::list_av_9<A1,A2,A3,A4,A5,A6,A7,A8,A9>::type> boost::bind(boost::type<T>,R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 11 arguments - 3 provided
1>        c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\bind\bind_mf2_cc.hpp(223) : see declaration of 'boost::bind'
1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(210) : error C2780: 'boost::_bi::bind_t<Rt2,boost::_mfi::mf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,_bi::list_av_9<A1,A2,A3,A4,A5,A6,A7,A8,A9>::type> boost::bind(boost::type<T>,R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7,B8),A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 11 arguments - 3 provided
1>        c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\bind\bind_mf2_cc.hpp(212) : see declaration of 'boost::bind'

Any compiler errors relating to boost are virtually unreadable and unhelpful to me, so I hope someone can help me figure out what is going on. Thanks in advance.

  • 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-31T12:42:59+00:00Added an answer on May 31, 2026 at 12:42 pm

    There are four overloads of std::string::find:

    size_t find(const string& str, size_t pos = 0) const;
    size_t find(const char* s, size_t pos, size_t n) const;
    size_t find(const char* s, size_t pos = 0) const;
    size_t find(char c, size_t pos = 0) const;
    

    Therefore one must help the compiler to pick one (resolve ambiguity) by specifying which particular overloaded function the address is taken of, e.g.:

    boost::bind( static_cast<size_t(std::string::*)(const std::string&, size_t) const>(&std::string::find), content_id, _1, 0)
    

    Rather ugly, isn’t it?

    Note, that std::string::find() returns std::string::npos (which most often is size_t(-1)) on an unsuccessful search. Then it would convert size_t(-1) to bool(true) and result in std::find_if() returning its first argument no matter what the rest of arguments are.

    The result of std::string::find() needs to be compared against std::string::npos. Using boost::bind that would look like:

    // ...
    
    std::vector<std::string>::iterator it = std::find_if(
          attachment_list_.begin()
        , attachment_list_.end()
        , boost::bind(
              std::not_equal_to<std::string::size_type>()
            , std::string::npos
            , boost::bind(
                  static_cast<size_t(std::string::*)(const std::string&, size_t) const>(&std::string::find)
                , &content_id // pass by pointer, don't copy
                , _1
                , 0)
                )
        );
    

    Which doesn’t look too readable either.

    It may be a tiny little bit more readable with boost::lambda::bind:

    #include <boost/lambda/bind.hpp>
    #include <boost/lambda/lambda.hpp>
    
    // ...
    
    std::vector<std::string>::iterator it =
        std::find_if(
              attachment_list_.begin()
            , attachment_list_.end()
            , boost::lambda::constant(std::string::npos) != boost::lambda::bind(
                  static_cast<size_t(std::string::*)(const std::string&, size_t) const>(&std::string::find)
                , &content_id // pass by pointer, don't copy
                , boost::lambda::_1
                , 0
                )
        );
    

    It looks most readable and elegant with C++11 lambda:

    std::vector<std::string>::iterator it = std::find_if(
          attachment_list_.begin()
        , attachment_list_.end()
        , [&content_id](std::string const& i) { return std::string::npos != content_id.find(i); }
        );
    

    Further I noticed that id returned for unsuccessful search is 0. It is the same value that is returned when the search succeeds on the first element. In other words, the caller of this function won’t be able to distinguish between an unsuccessful search and when the first (0th) element matched.

    It is most simple and portable to use a plain loop for search here:

    std::string* MimeDocument::GetAttachmentId(std::string const& content_id) {
        for(  std::vector<std::string>::iterator i(attachment_list_.begin()), j(attachment_list_.end())
            ; i != j
            ; ++i
            ) {
            if(std::string::npos != content_id.find(*i))
                return &*i;
        }
        return NULL;
    }
    

    Using this version the caller can easily tell between a successful and unsuccessful search and find out the matching index if necessary:

    MimeDocument doc;
    // ... populate doc
    if(std::string* found = doc.GetAttachmentId("1")) {
        // the search was successful.
        size_t found_index = found - &doc.attachment_list_.front();
    }
    

    So, pick your poison…

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

Sidebar

Related Questions

So...I have the following code: int main(void) { const char *s=hello, world; cout<<&s[7]<<endl; return
I have the following code: const int PROVIDER_RSA_FULL = 1; const string CONTAINER_NAME =
i have following code,which does not show me anything #include <iostream> using namespace std;
I have the following code int main() { int a=6; void *p; p=&a; p++;
i have the following code: private int[] GetIds<T>(string nameString) where T : DomainBase {
I have the following code: delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount); string
I have following code class Test { public: int &ref; int a; Test(int &x)
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
If I have the following Java code: int[][] readAPuzzle() { Scanner input = new
Let's say we have the following c++ code: int var1; __asm { mov var1,

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.