[Variant] recursive_wrapper and ambiguous convert_construct()
Hello,
I'm modelizing a syntax tree using boost::variant, std::tuple and
std::vector. This syntax tree has a lot of cyclic dependencies, so I have
to use boost::recursive_wrapper along with forward declarations.
I've encountered a case that my compiler (GCC 4.7) refuses to build.
Here is the source code: http://pastebin.com/3a5xU06x (it's pretty short)
Here is the compilation error message: http://pastebin.com/Zpa3TCp2
(Of course, reordering the declarations would solve the problem in this
example, but it's not the point. This is a constraint I can't get rid of
in my whole project.)
The compiler complains about an ambiguous call of convert_construct() in
Boost's source code, where a comment says:
NOTE TO USER :
Compile error here indicates that the given type is not
unambiguously convertible to one of the variant's types
(or that no conversion exists).
c can be converted to boost::recursive_wrapper
On Mon, Apr 9, 2012 at 8:48 AM, Florian Goujeon wrote: Hello, I'm modelizing a syntax tree using boost::variant, std::tuple and
std::vector. This syntax tree has a lot of cyclic dependencies, so I have
to use boost::recursive_wrapper along with forward declarations. I've encountered a case that my compiler (GCC 4.7) refuses to build.
Here is the source code: http://pastebin.com/3a5xU06x (it's pretty short)
Here is the compilation error message: http://pastebin.com/Zpa3TCp2 (Of course, reordering the declarations would solve the problem in this
example, but it's not the point. This is a constraint I can't get rid of
in my whole project.) The compiler complains about an ambiguous call of convert_construct() in
Boost's source code, where a comment says:
NOTE TO USER :
Compile error here indicates that the given type is not
unambiguously convertible to one of the variant's types
(or that no conversion exists). c can be converted to boost::recursive_wrapper I really don't know what to do. Help would be appreciated.
Thank you. It *looks* like it's getting confused with the conversion constructor that
constructs one variant type from another.
Let's see, it's trying to match
convert_construct(c_fwd&, long int)
and the candidates it's considering are
variant< rw
On 04/09/2012 08:23 PM, Jeffrey Lee Hellrung, Jr. wrote:
c_fwd inherits from c, which is the variant
that pops up above. So yeah, there's definitely an ambiguity there. Since boost.variant seems confused by this public inheritance, I'll try to write a wrapper instead:
class my_type { private: boost::variant<...> impl_; public: //interface of impl_ }; It's too bad C++ doesn't ease such writtings.
does that help you diagnose the problem in any way? It does. Thank you, Jeff!
On Wed, Apr 11, 2012 at 11:48 AM, Florian Goujeon < florian.goujeon@42ndart.org> wrote:
On 04/09/2012 08:23 PM, Jeffrey Lee Hellrung, Jr. wrote:
c_fwd inherits from c, which is the variant
that pops up above. So yeah, there's definitely an ambiguity there.
Since boost.variant seems confused by this public inheritance, I'll try to write a wrapper instead:
class my_type { private: boost::variant<...> impl_;
public: //interface of impl_ };
It's too bad C++ doesn't ease such writtings.
Well, it kinda does: inheritance; but it doesn't let you disable the derived -> base conversion :/ does that help you diagnose the problem in any way?
It does. Thank you, Jeff!
Hmmm, okay, that's good 'cause I've since forgotten the problem :) If you think some SFINAE trick can be used to disambiguate the constructor call, consider filing a trac ticket for Boost.Variant with this example. Or, if possible, an even simpler example, 'cause I remember finding even this stripped-down example hard to wrap my head around :/ And if you can provide a solution, even better! Again, I've since forgotten the problem, but I do remember that it wasn't immediately obvious to me whether this was a problem Boost.Variant should be able to handle or not. - Jeff
On 04/09/12 10:48, Florian Goujeon wrote:
Hello,
I'm modelizing a syntax tree using boost::variant, std::tuple and std::vector. This syntax tree has a lot of cyclic dependencies, so I have to use boost::recursive_wrapper along with forward declarations.
I've encountered a case that my compiler (GCC 4.7) refuses to build. Here is the source code: http://pastebin.com/3a5xU06x (it's pretty short) Hi Florian,
My brief look at your code puzzled me. I couldn't understand the purpose of a variant with only one member. I thought a variant was a tagged union where the value held in the tagged union was one of a set of types; yet, since there's only one type in the set, I can't fathom the reason for using a variant. Could you explain a bit? -regards, Larry
participants (3)
-
Florian Goujeon
-
Jeffrey Lee Hellrung, Jr.
-
Larry Evans