Hi Xavier, See here for an explanation: http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
Anyway, the basic purpose is to not fail building if a certain member function has a different name. I should have gotten our custom OSL branch in sync with the trunk name earlier, but now many people have OSL builds so I decided to keep it compiling using this trick. Brecht. On Wed, Dec 12, 2012 at 3:46 PM, Xavier Thomas <[email protected]> wrote: > Hi Brecht, > > Sorry to make noise here, but I thought I knew a bit of C++ templates and > cannot understand how this works. > Do you have a link that can help me understand what is going on here? > > Xavier > > > > > 2012/12/11 Brecht Van Lommel <[email protected]> > >> Revision: 52885 >> >> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52885 >> Author: blendix >> Date: 2012-12-11 14:39:32 +0000 (Tue, 11 Dec 2012) >> Log Message: >> ----------- >> Cycles: trick to make building with OSL trunk work as well, it has a >> different >> name for LoadMemoryShader so we make it call the right name depending on >> which >> is available. >> >> Modified Paths: >> -------------- >> trunk/blender/intern/cycles/render/osl.cpp >> >> Modified: trunk/blender/intern/cycles/render/osl.cpp >> =================================================================== >> --- trunk/blender/intern/cycles/render/osl.cpp 2012-12-11 14:39:30 UTC >> (rev 52884) >> +++ trunk/blender/intern/cycles/render/osl.cpp 2012-12-11 14:39:32 UTC >> (rev 52885) >> @@ -268,9 +268,43 @@ >> return shader_load_bytecode(bytecode_hash, bytecode); >> } >> >> +/* don't try this at home .. this is a template trick to use either >> + * LoadMemoryShader or LoadMemoryCompiledShader which are the function >> + * names in our custom branch and the official repository. */ >> + >> +template<bool C, typename T = void> struct enable_if { typedef T type; }; >> +template<typename T> struct enable_if<false, T> { }; >> + >> +template<typename T, typename Sign> >> +struct has_LoadMemoryCompiledShader { >> + typedef int yes; >> + typedef char no; >> + >> + template<typename U, U> struct type_check; >> + template<typename _1> static yes &chk(type_check<Sign, >> &_1::LoadMemoryCompiledShader>*); >> + template<typename > static no &chk(...); >> + static bool const value = sizeof(chk<T>(0)) == sizeof(yes); >> +}; >> + >> +template<typename T> >> +typename enable_if<has_LoadMemoryCompiledShader<T, >> + bool(T::*)(const char*, const char*)>::value, bool>::type >> +load_memory_shader(T *ss, const char *name, const char *buffer) >> +{ >> + return ss->LoadMemoryCompiledShader(name, buffer); >> +} >> + >> +template<typename T> >> +typename enable_if<!has_LoadMemoryCompiledShader<T, >> + bool(T::*)(const char*, const char*)>::value, bool>::type >> +load_memory_shader(T *ss, const char *name, const char *buffer) >> +{ >> + return ss->LoadMemoryShader(name, buffer); >> +} >> + >> const char *OSLShaderManager::shader_load_bytecode(const string& hash, >> const string& bytecode) >> { >> - ss->LoadMemoryShader(hash.c_str(), bytecode.c_str()); >> + load_memory_shader(ss, hash.c_str(), bytecode.c_str()); >> >> return loaded_shaders.insert(hash).first->c_str(); >> } >> >> _______________________________________________ >> Bf-blender-cvs mailing list >> [email protected] >> http://lists.blender.org/mailman/listinfo/bf-blender-cvs >> > _______________________________________________ > Bf-committers mailing list > [email protected] > http://lists.blender.org/mailman/listinfo/bf-committers _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
