|
Boost : |
Subject: Re: [boost] MSVC9 SFINAE quirks?
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2009-01-09 22:20:44
Steven Watanabe wrote:
> template <typename geometry_type_1, typename geometry_type_2>
> typename boost::enable_if<
> boost::mpl::and_<is_any_polygon_set_type<geometry_type_1>,
> is_any_polygon_set_type<geometry_type_2>,
> is_either_polygon_set_type<geometry_type_1,
>geometry_type_2>
> >,
> polygon_set_view<geometry_type_1, geometry_type_2, 3>
> >::type
> operator-(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
> return polygon_set_view<geometry_type_1, geometry_type_2, 3>
> (lvalue, rvalue);
> }
This won't work. In order to instantiate enable_if the compiler must instantiate both of its arguments. That means the compiler will try to instantiate polygon_set_view<> for every time the generic operator - in the stl is used for iterator arithmetic. Any error encountered trying to instantiate polygon_set_view will cause a syntax error and failed compilation even though the and_ evaluates to false.
To get around this I have added substitution failure when the first parameter is parsed:
template <typename geometry_type_1, typename geometry_type_2>
typename requires_1< typename gtl_if<typename gtl_and<
typename is_polygon_90_set_type<geometry_type_1>::type,
typename is_polygon_90_set_type<geometry_type_2>::type>::type>::type,
polygon_90_set_view<geometry_type_1, geometry_type_2, boolean_op::BinaryNot> >::type
operator-(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
return polygon_90_set_view<geometry_type_1, geometry_type_2, boolean_op::BinaryNot>
(lvalue, rvalue,
polygon_90_set_traits<geometry_type_1>::orient(lvalue),
boolean_op::BinaryNot());
}
requires_1 is equivalent to enable_if, gtl_if returns causes substitution failure unless it receives gtl_yes. I'm hoping MSVC will accept this syntax; gcc does just fine.
Regards,
Luke
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk