12

I've seen two recent answers using _1 as a pure C++0x solution (no explicit mention of boost lambdas).

Is there such an animal as std::_1 I would think that having native lambdas will make such a construct redundant.

A Google code search for std::_1 brings two results from the same project so that's inconclusive.

Community
  • 1
  • 1
Motti
  • 110,860
  • 49
  • 189
  • 262
  • do you think they would be in namespace std? In boost they are in the global namespace... – Armen Tsirunyan Oct 24 '10 at 19:00
  • 2
    [MSDN](http://msdn.microsoft.com/en-us/library/bb982158.aspx) has `_1` in a `std::placeholders` namespace and both your linked answers refer to that as well. This isn't conclusive either, but if nothing else you may be searching for the wrong thing. – Logan Capaldo Oct 24 '10 at 19:04
  • Oh, just found that they are in [TR1](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf) – Logan Capaldo Oct 24 '10 at 19:05

3 Answers3

13

Yes, they are part of C++0x inside the std::placeholders namespace, from the latest draft (n3126) §20.8.10.1.3 "Placeholders":

namespace std {
   namespace placeholders {
      // M is the implementation-defined number of placeholders
      extern unspecified _1;
      extern unspecified _2;
        .
        .
        .
      extern unspecified _M;
   }
}

They are actually included in TR1 (n1836 §3.6.4; n1455) along with bind, which are taken from the Boost.Bind library.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
5

Apparently they are part of C++ 0x and should be defined in the <functional> header in a conformant compiler, see the following FAQ:

C++ 0x FAQ

Hudson
  • 2,001
  • 1
  • 15
  • 17
Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
5

Yes, they are part of C++0x. I haven't double-checked the TR1 specs, but I suspect they were added there (TR1 was essentially a library-only extension to C++03, so it couldn't rely on lambdas), and then, since it's already there in TR1, it'd be needlessly disruptive to remove it again in C++0x, even though it's no longer really necessary once you have true lambdas.

jalf
  • 243,077
  • 51
  • 345
  • 550