Hy @ all, we have to realize the following functioncall:
std::mt19937 engine; color_table lut = create_random_color_map(engine);
The engine has to be exchangeable. We tried to implement it this way:
*.hpp
#include <tuple> #include <random> typedef std::tuple<unsigned char,unsigned char,unsigned char> rgb_tuple; class color_table{ public: [...] void generate(rgb_tuple predicate(const unsigned char& index)); }; template <class RANDOM> static rgb_tuple random_color(RANDOM engine){ std::uniform_int_distribution<int> dist1 (0,255); unsigned char red = (unsigned char) dist1(); unsigned char green = (unsigned char) dist1(engine); unsigned char blue = (unsigned char) dist1(engine); return std::make_tuple(red, green, blue); } template <class RANDOM> static color_table create_random_color_map(RANDOM engine){ color_table lut; lut.generate([&](const unsigned char& i)->rgb_tuple { return random_color<decltype(engine)>(engine); } ); return lut; } *.cpp
... void color_table::generate(rgb_tuple predicate(const unsigned char& index)){ for(int i = 0; i < 256; ++i){ std::tie(red_table[i], green_table[i], blue_table[i]) = predicate(i); } } When we try to compile, the following error occurs:
error C2664: 'color_table::generate': Convertion of the parameter 1 from 'create_random_color_map::' to 'rgb_tuple (__cdecl *)(const unsigned char &)' not possible 1>
No userdefined convertionoperator available, that can execute the convertion or the operator cannot be invoked. ... Function-template "color_table create_random_color_map(RANDOM)". with [
RANDOM=std::mt19937 ]
We are completely clueless about that failure and google isn't our friend in that case! :/
We appreciate any help!
Regards Hymir