variable parameter function, how to make it type safe and more meaningful?
<p>I am a newer for C++, and my first language is Chinese, so my words with English may be unmeaningful, say sorry first.
I know there is a way to write a function with variable parameters which number or type maybe different each calling, we can use the macros of va_list,va_start and va_end. But as everyone know, it is the C style. When we use the macros, we will lose the benefit of type-safe and auto-inference, then I try do it whit C++ template. My work is followed:</p>

<p><hr /></p>

<pre><code>#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;boost/any.hpp&gt;

struct Argument
{
    typedef boost::bad_any_cast bad_cast;

    template&lt;typename Type&gt;
    Argument&amp; operator,(const Type&amp; v)
    {
     boost::any a(v);
     _args.push_back(a);
     return *this;
    }

    size_t size() const
    {
     return _args.size();
    }

    template&lt;typename Type&gt;
    Type value(size_t n) const
    {
     return boost::any_cast&lt;Type&gt;(_args[n]);
    }

    template&lt;typename Type&gt;
    const Type* piont(size_t n) const
    {
     return boost::any_cast&lt;Type&gt;(&amp;_args[n]);
    }
private:
    std::vector&lt;boost::any&gt; _args;
};

int sum(const Argument&amp; arg)
{
    int sum=0;
    for(size_t s=0; s&lt;arg.size(); ++s)
    {
     sum += arg.value&lt;int&gt;(s);
    }

    return sum;
}

int main()
{
    std::cout &lt;&lt; sum((Argument(), 1, 3, 4, 5)) &lt;&lt; std::endl;

    return 0;
}
</code></pre>

<p><hr /></p>

<p>I think it's ugly, I want to there is a way to do better? Thanks, and sorry for language errors.</p>
