c++ - using c++11 auto as return type for const function object -
i have const function object , timebeing, returnes void. can return int or double. writing code in c++11 style , trying use auto return type. although code compiles, not sure 100% correct or not. here code.
template <typename graph_t> struct my_func { public: my_func() { } my_func (graph_t& _g) : g(_g) { } template <typename edge_t> auto operator()(edge_t edge) -> void const { //do edge. } //operator private: graph_t& g; }; //call functor: (pass graph g template parameter) std::for_each(beginedge, endedge, my_func<graph>(g));
this code compiles , works in serial mode perfectly. try parallelize above for_each using intel tbb parallel_for_each(). requires function object const. meaning threads should not allowed modify or change private variables of function object.
//tbb::parallel_for_each tbb::paralle_for_each(beginedge, endedge, my_func<graph>(g)); now, compiler error comes: passing const my_func< ... > .. discards qualifiers
so had change operator()() following:
template <typename edge_t> void operator()(edge_t edge) const { // } //operator
my question is: how use "auto operator()() ->void" , make operator "const" becomes valid ?
my question is: how use "auto operator()() ->void" , make operator "const" becomes valid ?
template <typename edge_t> auto operator()(edge_t edge) const -> void { //do edge. }
remember, declarator cv-qualifier has following form:
( parameter-declaration-clause ) cv-qualifier-seq [ref-qualifier] [exception-specification] [trailing-return-type]
(omitted attributes)
Comments
Post a Comment