Compile problem error: no matching constructor for initialization of 'std::vector'
The code base I am building has several objects that do not need to be variadic template parameters. I wanted to make them accept a vector of std::any. My objects are named after the HTML entities, such as H1, H2, PARAGRAPH.
The interface for object creation.
template <class TYPE>
auto _createElement(const std::vector<std::any> &attrs) -> TYPE & {
std::unique_ptr<TYPE> e = std::make_unique<TYPE>(attrs);
ViewManager::elements.push_back(std::move(e));
return static_cast<TYPE &>(*ViewManager::elements.back().get());
}
template <class TYPE, typename... ATTRS>
auto createElement(const ATTRS &... attribs) -> TYPE & {
std::vector<std::any> attrvector{attribs...};
return _createElement<TYPE>(attrvector);
}
The template parameter pack expansion into the vector on the createElement function is not compiling. The version I am using is c++17
When I call the template function, I am passing attribute objects to it. One within the template parameter that is likened to an HTML entity name, but all capitalized. And within the parameter pack are the attributes. The attributes are objects as well.
For example, the following is defined within the template header file viewManager.hpp
using PARAGRAPH = class PARAGRAPH : public Element {
public:
PARAGRAPH(const std::vector<std::any> &attribs)
: Element({listStyleType::disc, marginTop{1_em}, marginLeft{1_em},
marginBottom{0_em}, marginRight{0_em}}) {
setAttribute(attribs);
}
};
And in the application, like main.cpp
auto &mainArea = createElement<DIV>(
indexBy{"mainArea"}, objectTop{10_pct}, objectLeft{10_pct},
objectWidth{90_pct}, objectHeight{90_pct}, textColor{50, 50, 50},
background{100, 200, 200}, textFace{"FiraMono-Regular"},
textSize{20_pt}, textWeight{400});
As you can see, the syntax uses the user defined literals which return a numericFormat object.
The complete source as I have it so far can be seen at C++ Source. I want the any object to contain the data, not a pointer as you mentioned.