[過去ログ] C++相談室 part164 (1002レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
938: デフォルトの名無しさん (ワッチョイ 5d01-46Vy) [sage] 2023/10/23(月) 09:29:50.40 ID:9KLj8HWs0(1/2) AAS
>>936,937
あれ?
$ cat test.cpp
#include <iostream>
using namespace std;
struct A {
A () {cout << "construct" << endl;}
A (const A &p) = delete;
A (A &&p) {cout << "move" << endl;}
};
void func (initializer_list <A> p) {
cout << "func" << endl;
}
int main () {
A a0;
A a1;
func ({move (a0), move (a1)});
return 0;
}
$ g++ test.cpp
$ ./a.out
construct
construct
move
move
func
939(2): デフォルトの名無しさん (ワッチョイ 5d01-46Vy) [sage] 2023/10/23(月) 10:27:22.01 ID:9KLj8HWs0(2/2) AAS
だめかなぁ...
#include <vector>
struct A {
A(int) {}
A(const A&) = delete;
A(A&&) = default;
};
std::vector <A> construct (std::initializer_list <A> p) {
std::vector <A> result;
for (auto itr {p.begin ()}, end {p.end ()}; itr != end; ++ itr)
result.push_back (std::move (const_cast <A &> (*itr)));
return result;
}
int main()
{
std::vector<A> v = construct ({ 1, 2, 3 });
}
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.034s