Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store arguments list to vector?

How can I store variadic constructor arguments to vector?

Example with my failed tries:

class Combo 
{
public:
   template <class... Args>
   Combo(Args... args) 
   {
      // this->keys_.push_back(args...);

      // this->keys_.push_back(args)...;

      // this->keys_.push_back(std::forward<Args>(args...));

      //for (uint8_t arg : args...)
      //  this->keys_.push_back(arg);

      // ???
   }

private:
   std::vector<uint8_t> keys_;
};
like image 295
rabtors Avatar asked Dec 14 '22 08:12

rabtors


1 Answers

  1. C++11
for(auto &&i: {args...}) keys.push_back(std::move(i));
  1. C++17
(keys.push_back(args), ...);
  1. Oh, sorry, I've missed the obvious:
template<class... Args> Combo(Args... args): keys_{uint8_t(args)...} {}
like image 141
bipll Avatar answered Jan 02 '23 15:01

bipll