3

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?

rh0x
  • 1,066
  • 1
  • 13
  • 33
  • Please try to create a [Minimal, **Complete**, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us. And also please copy-paste the full error output (long as it might be with templates) as text into the question. – Some programmer dude Mar 03 '17 at 08:22

2 Answers2

6

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.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
3

For perfect forwarding, use a universal reference for the args parameter, and then forward it:

template< class Container, typename ... Args >
static void fillWithData(Container & oDataContainer, 
                         Args&& ... args)  // universal reference
{
    typedef typename Container::value_type::element_type QueueDataPtr;
    oDataContainer.emplace(new QueueDataPtr(std::forward<Args>(args)...));
}
Richard Hodges
  • 68,278
  • 7
  • 90
  • 142