Search code examples
c++c++11placeholderstdbind

Why start with std::placeholders::_1 instead of _0?


Most everything in c++ is 0, not 1 based. Just out of curiosity, why are placeholders 1 based? Meaning _1 is the first parameter, not _0.


Solution

  • Because that's how boost::bind does it, and the Boost.Bind author wrote the proposal to add it to TR1 and that got copied into the standard.

    As for why Boost.Bind does it that way, I don't know, but I would hazard a guess it might be to match std::bind1st and std::bind2nd from the 1998 standard, which came from the STL. In that context "1st" i.e. "first" is correct (even in a zero-based indexing system the item at index zero is the first, not the zeroth, item.)

    So maybe the placeholders should be _1st, _2nd, _3rd, _4th etc. but for non-English speakers who don't know the inconsistent suffixes on ordinal numbers it's probably easier to remember _1, _2 etc.

    Just a wild guess though. The question had never occurred to me so now I'm curious too :-)