Hi Everyone.
I am puzzled with a tough development task. I wonder if anyone is able to
find a good solution.
I want to re-implement tag boost::none. The current implementation is using
a pointer to member which allows a harmful conversion from literal 0. Try
this:
boost::optional orat = 0;
// this creates a disengaged optional.
I want to rewrite the definition with the following goals in mind:
1. boost::none_t is not implicitly convertible from literal 0;
2. The solution works in C++98
3. The solution is implementable in a header-only library. (defining some
member variable in a CPP file is not an option.
The only solution I was able to find so far is this:
[code]
struct none_t
{
enum creator_t {creator};
none_t(creator_t){}
};
namespace
{
none_t none (none_t::creator);
}
[/code]
It works, but I feel uncomfortable defining boost::none in every
translation unit. Any better ideas are welcome.
Regards,
&rzej