0

I'm stuck with a problem considering clang's behavior with c++ std::functional implementation. Well first things first: Here is some code that I'm trying to compile under MacOs Mavericks with XCode 5.0.2

#include <functional>
#include <ostream>

typedef std::function< std::ostream& (const void*, std::ostream&, uint32_t&, bool) > my_fancy_functor;

static void doSomething(const my_fancy_functor fcn)
{
   //... do something
}    

This results in a "Semantic Error" that holds the following text:

Implicit instantiation of undefined template 'std::__1::function<std::__1::basic_ostream<char> &(const void *, std::__1::basic_ostream<char> &, unsigned int &, bool *)>'

changing the typedef to a std::function that only gets three parameters will compile just fine

typedef std::function< std::ostream& (const void*, std::ostream&, uint32_t&) > my_fancy_functor;

Has anyone an idea what I'm doing wrong here. The code compiles fine with Visual Studio 2010-2013 as well as with gcc version > 4.7.0

As of now I'm sure it has nothing to do with the std::ostream used inside the functional. Substituting any of the types used inside this example with any other imaginable type will result in just the same error message, which brings me to believing that there could be something wrong with the implementation of the std::functional itself.

Any help or hint which helps me resolving this mess will be much appreciated!

mschmieder
  • 73
  • 8

1 Answers1

3

Set the C++ Language Dialect to C++11 [-std=c++11] or GNU++11 [-std=gnu++11] in your Build Settings and it's going to compile just fine.

Ivan Genchev
  • 2,746
  • 14
  • 25
  • Thanks Ivan, I found out just minutes ago that I have to enable c++11 features. Since I'm using CMake to configure my projects I had to add set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") – mschmieder Dec 18 '13 at 15:47