|
Boost Users : |
Subject: Re: [Boost-users] boost::variant and SFINAE
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-12-03 09:23:57
2009/12/3 Jonathan Chambers` <chamber_j_at_[hidden]>:
>
> I'm trying to get the program to compile if the variant takes on the guise
> of an int (because I've implemented void operator()(int &i) const, but not
> compile if I make the variant take the guise of a char e.g.
> boost::variant<int, char> var = 'a'; because I've not implemented the void
> operator()(char &c) const
>
> Can anyone think of a way of doing this, maybe using SFINAE (Substitution
> Failure Is Not An Error)
>
I don't think SFINAE will help here, since you don't have a template.
What about just declaring, but not defining, the version with a char
parameter?
Though since it's a runtime distinction, I'm not convinced this will
be possible at compile-time, since it will want to compile the code
for all the runtime possibilities.
What's wrong with just throwing an exception in the char-parameter
function in the visitor? Or, alternatively, why are you using a
variant<char, int> if you never want it to be a char?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net