I'm trying to accomplish something similar to Eigen advanced initialization for my container class.
i.e. in main, I want to fill an object of type DynamicArray as follows:
main.cpp
// Create 3 x 3 Dynamic array and fill with 0's DynamicArray da(3, 3, 0); da << 1, 2, 3, 4, 5, 6, 7, 8, 9; The method I've used to try to accomplish this is:
DynamicArray.hpp
template <typename T> class DynamicArray { // ... public: // ... template <typename... Args, typename = typename std::enable_if<ArgPackSameTruth< std::is_convertible<Args, T>...>::value, T>::type > void operator<<(Args... x) { typename std::vector<T> arg_vect{std::forward<Args>(x)...}; std::cout << arg_vect.size() << "\n"; // Load contents of arg_vect into *this... return; } } When I compile main.cpp, I get a size of 1 for arg_vect, so only the first parameter is being taken in. How can I make sure all parameters are passed?
Thanks!
*thisso that it can become possible to chainda << 1 << 2 //...calls.