mirror of https://github.com/CGAL/cgal
workaround user taking ref to temporary
If D is a temporary, it's lifetime extension is done when we go out of the scope of choose_parameter so the const D& returned is dangling
This commit is contained in:
parent
abddb30bd7
commit
1eda841d32
|
|
@ -313,6 +313,12 @@ const D& choose_parameter(const internal_np::Param_not_found&, const D& d)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename D>
|
||||||
|
D choose_parameter(const internal_np::Param_not_found&, D&& d)
|
||||||
|
{
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, typename D>
|
template <typename T, typename D>
|
||||||
T& choose_parameter(T& t, D&)
|
T& choose_parameter(T& t, D&)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,13 @@ void test_values_and_types(const NamedParameters& np)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class NamedParameters>
|
template<class NamedParameters>
|
||||||
void test_no_copyable(const NamedParameters&)
|
void test_no_copyable(const NamedParameters& np)
|
||||||
{
|
{
|
||||||
typedef typename inp::Get_param<typename NamedParameters::base,inp::visitor_t>::type NP_type;
|
typedef typename inp::Get_param<typename NamedParameters::base,inp::visitor_t>::type NP_type;
|
||||||
static_assert( boost::is_same<NP_type,std::reference_wrapper<const B> > ::value );
|
static_assert( boost::is_same<NP_type,std::reference_wrapper<const B> > ::value );
|
||||||
|
|
||||||
|
const A<4>& a = params::choose_parameter(params::get_parameter_reference(np, inp::edge_index), A<4>(4));
|
||||||
|
assert(a.v==4);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class NamedParameters>
|
template <class NamedParameters>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue