Opened 3 years ago

Last modified 3 years ago

#11902 new Bugs

bind placeholder _1 is not defined

Reported by: zimmermann@… Owned by: Peter Dimov
Milestone: To Be Determined Component: bind
Version: Boost 1.60.0 Severity: Problem
Keywords: Cc:


bind placeholder _1 is not defined in version 1.60.0 .


#include <boost/bind/bind.hpp>

int f(int a, int b) { return a + b; }

int main(void)
  int x = 1;
  int a = boost::bind(f, 5, _1)(x);

 return 0;

Compiler output:

bind_error.cpp: In function ‘int main()’:
bind_error.cpp:11:29: error: ‘_1’ was not declared in this scope
   int a = boost::bind(f, 5, _1)(x);
bind_error.cpp:11:29: note: suggested alternative:
In file included from /home/projekte/libwinforwiss/boost/boost_1_60_0/boost/bind/bind.hpp:2247:0,
                 from bind_error.cpp:1:
/home/projekte/libwinforwiss/boost/boost_1_60_0/boost/bind/placeholders.hpp:46:38: note:   ‘boost::placeholders::_1’
 BOOST_STATIC_CONSTEXPR boost::arg<1> _1;

Replacing _1 with boost::placeholders::_1 works for 1.60.0 , but not for 1.59.0.

Change History (3)

comment:1 Changed 3 years ago by Raffi Enficiaud

I have the same problem, but only on Visual.

comment:2 Changed 3 years ago by viboes

Component: Nonebind
Owner: set to Peter Dimov

comment:3 Changed 3 years ago by Peter Dimov

This is by design; from now on, #include <boost/bind/bind.hpp> defines _1 in namespace boost::placeholders without importing it into the global namespace, to avoid conflicts. For backward compatibility, #include <boost/bind.hpp> includes boost/bind/bind.hpp and does using namespace boost::placeholders;.

So, to make the code compile, either include boost/bind.hpp instead, or add using namespace boost::placeholders;.

Note: See TracTickets for help on using tickets.