Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Judging from your comment, what you mentioned can be implemented probably by making a predicate class which determines whether the specified class has the member function, and using <code>fusion::filter_view</code>. <code>DEF_HAS_MEM_FUNC</code> macro in the following code is explained at:</p> <p><a href="https://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence/264088#264088">Is it possible to write a template to check for a function&#39;s existence?</a></p> <pre><code>#include &lt;boost/fusion/include/cons.hpp&gt; #include &lt;boost/fusion/include/filter_view.hpp&gt; #include &lt;boost/fusion/include/for_each.hpp&gt; #include &lt;boost/mpl/placeholders.hpp&gt; using namespace boost; #define DEF_HAS_MEM_FUNC( name, func_name, signature ) \ template&lt; class T &gt; \ struct name { \ template&lt; class U, U &gt; struct mfp; \ \ template&lt; class U &gt; \ static char f( mfp&lt; signature, &amp;U::func_name &gt;* ); \ \ template&lt; class &gt; static char (&amp;f(...))[2]; \ \ enum { value = (sizeof( f&lt;T&gt;(0) ) == 1) }; \ } DEF_HAS_MEM_FUNC( has_f, f, void(U::*)()const ); struct DoSomething { template&lt; class U &gt; void operator()( U&amp; u ) const { u.f(); } }; struct A {}; struct B { void f() const {} }; typedef fusion::cons&lt; A, fusion::cons&lt; B &gt; &gt; MyTuple; int main() { MyTuple tuple_; fusion::filter_view&lt; MyTuple const, has_f&lt; mpl::_ &gt; &gt; v( tuple_ ); fusion::for_each( v, DoSomething() ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload