ULTRA-PERFECT FORWARDING
そういえば, template<class T> Hoge( T && x ); っていう ctor が有った場合,
2012-03-05 00:36:56Hoge x, y = x; こう書いた時って,コピーコンストラクタじゃなくてテンプレートのコンストラクタが呼ばれるんだけど,これって酷い落とし穴だよね.
2012-03-05 00:37:30この動作を避けるには, template<class T, class = std::enable_if<!std::is_same<Hoge, typename std::decay<T>::type>::value>::type> Hoge( T && x );
2012-03-05 00:39:00あ,今の SFINAE は最低限で,本来は is_convertible とかを使って さらに T の条件を restrict しないとダメ.
2012-03-05 00:40:19@SubaruG In addition to that issue, C++ specialists have to know how to control constructibility/no-throwness of Hoge.
2012-03-05 00:42:05ですね. 僕は https://t.co/slZudG3V の 243 行以降みたいな感じで 基底クラスを使って何とかしましたが,なかなか気付けないです. http://t.co/ZYwaFMaI
2012-03-05 00:47:07本体クラスでは copy/move は必ず defaulted にして,その基底クラスで条件ごとに copy/move を殺す. っていうのが,今のところ一番スマートかなって思います. copy/move をテンプレートにすると,非テンプレートの自動生成が優先されちゃうのが痛い.
2012-03-05 00:50:22@SubaruG But the story could become more complicated. You may be tempted to disable non-template default-, move-, copy-constructors.
2012-03-05 00:50:25@Cryolite えーと,すみません. さっきのコードみたいに,基底クラスを使って ごちゃごちゃやるのの,何が問題なのでしょう? (ごちゃごちゃになるのは問題に決まってますが
2012-03-05 00:54:03@SubaruG Ah, yes. I read the default etude::optional implementation. It is fine with explicitly defaulted ctors with controlled base classes
2012-03-05 00:55:14@SubaruG In short, e.g., is std::is[_nothrow]_constructible<optional<T>, T> true iff std::is[_nothrow]_constructible<T, T> is true?
2012-03-05 00:57:10@SubaruG Of course, there are similar questions w.r.t. its cv-qualification variants.
2012-03-05 01:00:37@SubaruG ...and w.r.t. its variants different in the value category, of course.
2012-03-05 01:03:46@Cryolite 把握している限りは対応してますが,果てしなく面倒なのは確かですね. 僕としては, ctor の第一引数を型推論させるのは止める方針になりつつあります
2012-03-05 01:05:27あ, optional のテストは,ロクにやってないです. optional を書いてて, Etude のプログラミングポリシーをきっちり考え直す必要に迫られたので
2012-03-05 01:20:49C(ry センセのいうことは尤もで,僕も日頃からそれを考えていたので,正直 テンプレートは避けるべきという結論に至りつつ有る次第. Move があるしね.
2012-03-05 01:07:37T_ const& と T_ && を取る ctor ,および emplace_construct を取る ctor などを作って, U && で推論させる ctor は無しにしようと.
2012-03-05 01:11:10@Cryolite explicit/非explicitを問わず, ctor の第一引数を, U& や U const& や U&& で推論させるのはやめよう,って感じです. SFINAE するのでテンプレートにはしますが
2012-03-05 01:15:01@SubaruG template< class U = T, class = typename enable_if<( U を使った条件式)>::type > 美味しいです
2012-03-05 01:15:51