MCPcopy Create free account
hub / github.com/0voice/cpp_new_features / main

Function main

cpp_14/001_utility_exchange.cpp:28–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26void f() { std::cout << "f()"; }
27
28int main()
29{
30 stream s;
31
32 std::cout << s.flags() << '\n';
33 std::cout << s.flags(12) << '\n';
34 std::cout << s.flags() << "\n\n";
35
36 std::vector<int> v;
37
38 // 因为第二模板形参有默认值,故能以花括号初始化列器表为第二参数。
39 // 下方表达式等价于 std::exchange(v, std::vector<int>{1,2,3,4});
40
41 std::exchange(v, {1,2,3,4});
42
43 std::copy(begin(v),end(v), std::ostream_iterator<int>(std::cout,", "));
44
45 std::cout << "\n\n";
46
47 void (*fun)();
48
49 // 模板形参的默认值亦使得能以通常函数为第二参数。
50 // 下方表达式等价于 std::exchange(fun, static_cast<void(*)()>(f))
51 std::exchange(fun,f);
52 fun();
53}

Callers

nothing calls this directly

Calls 2

flagsMethod · 0.80
funFunction · 0.50

Tested by

no test coverage detected