CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Unhappy Question about bind2nd.

    Hi, everyone!

    Here is an example about the usage of
    bind2nd. But I do not understand what the
    function is doing. I have used MSDN to find
    help, but still puzzled because there is only
    a little of material on the topic.


    Who can tell me what is the function doing in
    the following example?


    --------
    vector<int> v;
    // fill v with 4 6 10 3 13 2
    int bound = 5;

    replace_if (v.begin(), v.end(), bind2nd (less<int>(), bound), bound);

    // v: 5 6 10 5 13 5

    --------


    Thanks in advance,
    George

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449
    The function replaces all values less than 5 with 5. The bind2nd calls less<> with the value of 5, which serves as a predicate to replace_if().

    Check your private messages.

    Regards,

    Paul McKenzie

  3. #3
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    Hi, Paul buddie!

    What means "predicate" in your reply?


    Thanks in advance,
    Geroge

  4. #4
    Join Date
    Apr 2000
    Location
    Frederick, Maryland
    Posts
    507
    Predicate means a function or function object which return true or false. If it takes one parameter then it is called unary predicate and if it takes two parameter then it is called binary predicate. For example

    Code:
    bool less_than_10(int no)
    {
        return no < 10;
    }
    or

    Code:
    class less_than_10
    {
    public:
         bool operator ()(int no)
         {
               return no < 10;
          }
    };
    Note: Usually these are made template.

    Hope it helps.
    Last edited by Zeeshan; February 16th, 2003 at 03:26 AM.

  5. #5
    George2 is offline Elite Member Power Poster
    Join Date
    Oct 2002
    Posts
    4,468

    Talking

    Thanks, Zeeshan buddie!

    George

    Originally posted by Zeeshan
    Predicate means a function or function object which return true or false. If it takes one parameter then it is called unary predicate and if it takes two parameter then it is called binary predicate. For example

    Code:
    bool less_than_10(int no)
    {
        return no < 10;
    }
    or

    Code:
    class less_than_10
    {
    public:
         bool operator ()(int no)
         {
               return no < 10;
          }
    };
    Note: Usually these are made template.

    Hope it helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured