Search code examples
c++compiler-errorsvariadic-templatesargument-unpacking

Variadic template: error: parameter packs not expanded with '...'


I'm trying to pass multiple strings to fill a Container, but I receive this error. Using gcc 4.9.3

template< class T >
struct DataCompare {
    bool operator()( const T& lhs, const T& rhs ) const
    {
        return operator<( lhs->getCode(), rhs->getCode() );
    }
};

using AggContainer = boost::container::flat_set< T, C >; 
using DataPtr      = boost::shared_ptr< BomQueueData >;
using PropertyQueueDataLess = DataCompare< DataPtr >;
using QueueDataPtrs = AggContainer< DataPtr, DataLess >;

QueueDataPtrs vector_name;

template< class Container, typename ... Args >
static void fillWithData(Container & oDataContainer, Args const & ... args)
{
    typedef typename Container::value_type::element_type QueueDataPtr;
    oDataContainer.emplace(new QueueDataPtr(args));
}

fillWithData(vector_name, x, a, b, c, d); // compiler error

How to solve?


Solution

  • args is a parameter pack, not a parameter. That's why you can't use:

    DataContainer.emplace(new QueueDataPtr(args));
    

    Instead, use

    DataContainer.emplace(new QueueDataPtr(args...));
    

    That expands the parameter pack.