> On 20 Jan 2015, at 09:57, Akim Demaille <a...@lrde.epita.fr> wrote: > > >> Le 19 janv. 2015 à 23:14, Hans Aberg <haber...@telia.com> a écrit : >> >> >>> On 19 Jan 2015, at 18:35, Akim Demaille <a...@lrde.epita.fr> wrote: >>> >>>> Le 19 janv. 2015 à 14:28, Hans Aberg <haber...@telia.com> a écrit : >>>> >>>> So it may suffice to have move constructors in the class variant. >>> >>> Right. With #if around them :) >> >> I succeeded in replacing all copying with move operations in the calc++ >> example! > > That's good news, thanks for the experimentation!
Just for the record, I was able to fix the combined r- and r-value template: template <typename T> variant (T&& t) : yytypeid_ (&typeid (T)) { YYASSERT (sizeof (T) <= S); typedef std::remove_reference_t<T> T1; new (yyas_<T1> ()) T1 (std::forward<T>(t)); } One then has to add template <typename T> T* yyas_ () & { void *yyp = yybuffer_.yyraw; return static_cast<T*> (yyp); } And in addition l-value calls: basic_symbol (typename Base::kind_type t, const Int& v, const location_type& l); basic_symbol (typename Base::kind_type t, Int& v, const location_type& l); basic_symbol (typename Base::kind_type t, Int&& v, const location_type& l); static inline symbol_type make_NUMBER (const Int& v, const location_type& l); static inline symbol_type make_NUMBER (Int& v, const location_type& l); static inline symbol_type make_NUMBER (Int&& v, const location_type& l); template <typename Base> calcxx_parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const Int& v, const location_type& l) : Base (t) , value (v) , location (l) {} template <typename Base> calcxx_parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, Int& v, const location_type& l) : Base (t) , value (v) , location (l) {} template <typename Base> calcxx_parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, Int&& v, const location_type& l) : Base (t) , value (std::move(v)) , location (l) {} calcxx_parser::symbol_type calcxx_parser::make_NUMBER (const Int& v, const location_type& l) { return symbol_type (token::TOK_NUMBER, v, l); } calcxx_parser::symbol_type calcxx_parser::make_NUMBER (Int& v, const location_type& l) { return symbol_type (token::TOK_NUMBER, v, l); } calcxx_parser::symbol_type calcxx_parser::make_NUMBER (Int&& v, const location_type& l) { return symbol_type (token::TOK_NUMBER, std::move(v), l); }