I wish get rid of boost dependency on my code. I have the following struct construct. When calling and using this struct at another place in the code boost::any_cast
is used. I know a template class would do it, but finding it hard to write this template. - C++ Rookie.
struct Properties {
public:
Properties() {}
Properties(const std::string &s, const boost::any & p) {
name = s;
value = p;
}
template <typename T>
Properties(T n) {
value = n;
}
boost::any value;
std::string name;
};
Just for fun, I thought I'd create a minimalist any implementation:
You can then use it precisely the same fashion as your use-cases showed:
See the output Live On Coliru