From: igodard@pacbell.net   
      
   On 9/6/2012 5:48 PM, Daniel Krügler wrote:   
   > Am 06.09.2012 23:05, schrieb Ivan Godard:   
   >> As for "easy to figure out", call me dense but it sure wasn't easy   
   >> for me. Even Daniel's solution, while solving my problem with   
   >> scoped enums, does not provide a general solution to discovering   
   >> whether a particular operation is defined.   
   >   
      
      
      
   > I'm not sure that I properly understand your question, but it seems   
   > as if you have to call the function foo or bar, so you need to know   
   > the arguments you have to provide. In your snippet above you seem to   
   > assume functions with no parameters.   
   >   
   > From what I understand from your question, most parts should be   
   > quite easy to realize with C++11 because of the extended sfinae   
   > capabilities. Here is the result of a 7-min-coding:   
   >   
   > #include    
   > #include    
   >   
   > template   
   > struct has_member_foo {   
   > template class = decltype(std::declval().foo(std::declval()...))   
   > >   
   > static std::true_type test(int);   
   > template   
   > static std::false_type test(...);   
   > static constexpr bool value = decltype(test(0))::value;   
   > };   
   >   
   > template   
   > struct fooOrBarHelper {   
   > template   
   > void operator()(T&& t, Args&&... args) {   
   > std::forward(t).foo(std::forward(args)...);   
   > }   
   > };   
   >   
   > template<>   
   > struct fooOrBarHelper {   
   > template   
   > void operator()(T&& t, Args&&... args) {   
   > std::forward(t).bar(std::forward(args)...);   
   > }   
   > };   
   >   
   > template   
   > void fooOrBar(T&& t, Args&&... args) {   
   > fooOrBarHelper::value>()(   
   > std::forward(t), std::forward(args)...   
   > );   
   > }   
   >   
      
   I guess it depends on what you consider "easy", which the above is not   
   in my book :-)   
      
      
   Generalization question: your has_member_foo tests for a specific   
   member. Can it be written to test for an arbitrary member that is an   
   argument to the test? That is, is   
    has_member(someMemberName)   
   possible, testing whether std::declval().someMemberName() exists   
   for an argument member name? I don't see how the desired member name   
   could be passed; pointer-to-member seems to beg the question.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|