std algorithm functions do not compile in certain case - by cubee_q

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 669603 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 5/20/2011 6:30:39 AM
Access Restriction Public


When using std algorithm functions inside a lambda, inside an initializer list, the code only compiles when writing a "using namespace std". Fully qualifying the name with "std::" or "::std::" results in an "error C2039: 'copy_if' : is not a member of 'std'"

Look at the code below to get an idea : 

#include "stdafx.h"
#include "assert.h"
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <utility>

class CMyClass
    CMyClass( const std::vector< int > & ac_Values )
    : mc_Values( [ & ac_Values ]() -> std::vector< int >
      std::vector< int > lv_Values ;

      std::copy_if( ac_Values.begin(), ac_Values.end(), std::back_inserter( lv_Values ), []( const int ) { return true ; } ) ;   

        // DOES COMPILE
      using namespace std ;
      copy_if( ac_Values.begin(), ac_Values.end(), back_inserter( lv_Values ), []( const int ) { return true ; } ) ;
      return lv_Values ;     
    } () )

    const std::vector< int > mc_Values ;

int _tmain(int argc, _TCHAR* argv[])
  CMyClass a( std::vector< int >( 10, 1 ) ) ;
 	return 0;
Sign in to post a comment.
Posted by Microsoft on 6/11/2011 at 7:24 PM
    A fix for this issue has been checked into the compiler sources.
    The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Compiler Team
Posted by MS-Moderator07 [Feedback Moderator] on 5/22/2011 at 9:31 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator07 on 5/22/2011 at 7:10 PM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly (