Juce and C++11?


#1

With last commits i get a bunch of errors with "static void callAsync (std::function<void(void)>);" function. I guess it is due to my old compiler (gcc-4.2) that doesn't support C++11. Is that mean that JUCE will not support anymore pre C++11 compiler? In that case it should be fair to tag JUCE according to that switch, isn'it?

http://www.juce.com/forum/topic/pb-new-commit


#2

Sigh.. I actually thought std::function had been around since c++03, but if it's going to cause problems for old compilers I'll find a way to disable it.


#3

I'm pretty sure only VS2010 and up support lambdas. Haven't gotten VS2005 or VS2008 kicking around anymore to test that out, but I do recall they both sucked at C++03 and C++11 support.


#4

Thanks, compiles fine now on Xcode's GCC 4.2 with the workaround!

I suppose that at a point in the future old compiler support will ended in order to use new C++11 features. Is there a plan about that?


#5

Yes, one day we'll be able to use the fancy new features, but it really just depends how many people are still building for old systems.

There are some annoyances like the fact that OSX 10.6 doesn't have the right libraries for c++11 so you can't use it to build an app that's backwards compatible. But eventually the world will move on!


#6

Keep on adding the C++11 stuff! I had myself already done a little helper function to do the "run callable in message thread" thing, but all the better if it exists in Juce built-in.

My version is a bit more cryptic as it has just this stand-alone function and it allows passing in function call parameters too. I've so far tested this only on Windows (VS2013) but I wouldn't expect this to fail with the latest Clang on OS-X either.

 


template<typename F,typename... Args>
inline void run_in_message_thread(F&& f,Args&&... args)
{
  auto bind_result=std::bind(std::forward<F>(f),std::forward<Args>(args)...);
  using bind_result_t=decltype(bind_result);
  auto p=[](void* ctx)->void*
  {
    bind_result_t* f_=static_cast<bind_result_t*>(ctx);
    (*f_)();
    return nullptr;
  };
#ifdef WIN32
  MessageManager::getInstance()->callFunctionOnMessageThread((juce::MessageCallbackFunction(__cdecl*))p,
  &bind_result);
#endif
}

#7

Compiling the juceDemo with Apple LLVM 4.1 and -std=c++11 I got error "No type named 'function' in namespace std"

Do I miss a project setting or something?


#8

Try again now.


#9

ok, 10.9+ only! :) thanks jules. 

Btw, is there any compiler you recommand ?