Variadic function with restricted types I am designing a class which (among other things) acts as a vertex in an undirected graph.

#include &lt;iterator&gt;
#include &lt;string&gt;

class Node
{
public:
    explicit Node(const std::string&amp; name);
    Node(const Node&amp;);
    Node(Node&amp;&amp;);

    class iterator
        : public std::iterator&lt;std::random_access_iterator_tag, const Node&gt;
    {
        //...
    };
    class container_proxy
    {
    public:
        iterator begin() const;
        iterator end() const;
    private:
        //...
    };

    container_proxy neighbors() const;

    add_link(Node&amp; other);

    //...

private:
    //...
};
// to support: for (const Node&amp; neighbor : node.neighbors())
Node::iterator begin(const Node::container_proxy&amp;);
Node::iterator end(const Node::container_proxy&amp;);


Now I want to define a function link_complete which:


takes any number of arguments
allows non-const Node lvalues (parameter type Node&amp;)
allows non-const Node rvalues (parameter type Node&amp;&amp;)
does not allow any other parameter type.


An example usage:

Node ret_by_value();

void example_test(Node&amp; x, Node&amp;&amp; y)
{
    link_complete(x, ret_by_value(), std::move(y), Node("test"));
}


Here's the solution I came up with:

#include &lt;initializer_list&gt;
#include &lt;type_traits&gt;

class Node {
    //...
public:
    static void link_complete(std::initializer_list&lt;Node*&gt; node_list);
};

template &lt;typename ... Types&gt;
struct template_all; // UNDEFINED

template &lt;&gt;
struct template_all&lt;&gt;
  : public std::true_type {};

template &lt;typename ... Types&gt;
struct template_all&lt;std::false_type, Types...&gt;
  : public std::false_type {};

template &lt;typename ... Types&gt;
struct template_all&lt;std::true_type, Types...&gt;
  : public template_all&lt;Types...&gt;::type {};

template &lt;typename ... Args&gt;
auto link_complete(Args&amp;&amp; ... args) -&gt;
  typename std::enable_if&lt;
    template_all&lt;
      typename std::is_same&lt;
        typename std::remove_reference&lt;Args&gt;::type,
        Node
      &gt;::type ...
    &gt;::value,
    void
  &gt;::type
{
    Node::link_complete( { &amp;args... } );
}


It seems to work as required, but I'm wondering if there was a simpler or "prettier" way to do it, or maybe a way to improve that template_all helper type.  All C++11, TR1, and Boost features are welcome.  I did notice boost::mpl::and_ looks similar to my template_all helper type, but Boost MPL seems like a tricky learning curve and/or overkill for this problem.
struct has public inheritance

By default, struct has public inheritance. Therefore, you don't need to manually specify it every time. You can write shorter (and so more readable) code:

template &lt;&gt;
struct template_all&lt;&gt;
  : std::true_type {};

template &lt;typename ... Types&gt;
struct template_all&lt;std::false_type, Types...&gt;
  : std::false_type {};

template &lt;typename ... Types&gt;
struct template_all&lt;std::true_type, Types...&gt;
  : template_all&lt;Types...&gt;::type {};


Since type traits generally use many templates, you don't want to add even more extra keywords all over the place.

Use alias templates

If you have acces to a compiler that supports some C++14 features, you will probably want to use the alias templates for transformation traits to get rid of many typename and ::type. Unfortunately, the alias templates for the query traits (is_*) have not been accepted, so you have to use std::is_same.

template &lt;typename ... Args&gt;
auto link_complete(Args&amp;&amp; ... args) -&gt;
  std::enable_if_t&lt;
    template_all&lt;
      typename std::is_same&lt;
        std::remove_reference_t&lt;Args&gt;,
        Node
      &gt;...
    &gt;::value,
    void
  &gt;
{
    Node::link_complete( { &amp;args... } );
}


static_assert is great

Instead of using SFINAE for link_complete, you should use static_assert since your function does not have any overload. It will allow you to give a meaningful error message instead of a somewhat obscure SFINAE error message:

template &lt;typename ... Args&gt;
void link_complete(Args&amp;&amp; ... args)
{

    static_assert(
        template_all&lt;
            typename std::is_same&lt;
                std::remove_reference_t&lt;Args&gt;,
                Node
            &gt;::type...
        &gt;::value,
        "link_complete arguments must be of the type Node"
    );

    Node::link_complete( { &amp;args... } );
}


You may want to use std::decay

std::decay calls std::remove_reference and std::remove_cv internally. If needed, it also calls std::remove_extent if T is an array type and calls std::add_pointer if T is a function type. In short:


  This is the type conversion applied to all function arguments when passed by value.


That allows you to check for what we generally think of as "same types":

template &lt;typename ... Args&gt;
void link_complete(Args&amp;&amp; ... args)
{

    static_assert(
        template_all&lt;
            typename std::is_same&lt;
                std::decay_t&lt;Args&gt;,
                Node
            &gt;::type...
        &gt;::value,
        "link_complete arguments must be of the type Node"
    );

    Node::link_complete( { &amp;args... } );
}


Rethink template_all

All in all, your goal is to test boolean conditions on types. Since the query traits have a static constexpr bool value member, you may want to create a template_all that checks for true and false (like std::enable_if or std::conditional) instead of checking for std::true_type and std::false_type. That would make your intent clearer, but it would be more like a all_true template.

template &lt;bool...&gt;
struct all_true; // UNDEFINED

template &lt;&gt;
struct all_true&lt;&gt;
  : std::true_type {};

template &lt;bool... Conds&gt;
struct all_true&lt;false, Conds...&gt;
  : std::false_type {};

template &lt;bool... Conds&gt;
struct all_true&lt;true, Conds...&gt;
  : all_true&lt;Conds...&gt; {};

template &lt;typename ... Args&gt;
void link_complete(Args&amp;&amp; ...)
{
    static_assert(
        all_true&lt;
            std::is_same&lt;
                std::decay_t&lt;Args&gt;,
                Node
            &gt;::value...
        &gt;::value,
        "must have Node types"
    );

    Node::link_complete( { &amp;args... } );
}