EDIT: boost::any using bcp (thanks AraK) seems to be the best solution to date but is it possible to prove (to some extent) that there exists no ANSI C++ solution to this problem?
You seem a bit confused about the terminology here.
First, let's call it ISO C++, shall we? It was standardized by ISO in 1998, and since then, that is what people have referred to when talking about "standard C++".
Now, what do you mean by an "ANSI C++ solution"?
- A solution that compiles cleanly using only ANSI (or ISO) C++? If so, Boost is the ANSI C++ solution
- A solution already implemented in the ANSI C++ standard library? If so then no, no such solution exists (and there is no "proof", other than "go read through the language standard and see if you can find such a class. If you can't, it isn't there".
- A solution you could implement yourself using only ANSI C++. Then the answer is "yes, you could go copy the source code from Boost".
I can't imagine what kind of "proof" you'd be looking for. C++ is a document in prose form. It is not a mathematical equation. It can not be "proven", except by saying "go read the standard". Proving that something is defined in the language or in the standard library is easy -- simply point out where in the standard it is described. But proving that something isn't there is basically impossible -- except by enumerating every single sentence of the standard, and document that none of them describe what you're looking for. And I doubt you'll find anyone willing to do that for you.
Anyway, the correct standard C++ solution is to use Boost.
It is not a heavy-weight solution. Boost is pretty lightweight in that you can include exactly the bits you need, with no dependencies on the rest of the library collection.
From what you've described (a light application for a broad user base), there is zero reason not to use Boost. It can simplify your code and reduce the number of bugs caused by attempting to reinvent the wheel. When distributing the compiled executable, it has zero cost. The Boost.Any
library is, like much of Boost, header-only, and is simply compiled into your executable. No separate libraries have to be distributed.
There is nothing to be gained by trying to reinvent the wheel. Your executable will be no smaller or more efficient, but it will be more buggy.
And I'm willing to bet that your home-brewed solution will not be ANSI C++. It will rely on some form of undefined behavior. If you want an ANSI-C++ solution, your best bet is Boost.