Fix 22_locale/locale/cons/12658_thread-2.cc on hppa.
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / synchronized_value.cc
blob8e8134699a2f3f82b0248b940869ff319e8fcb07
1 // { dg-do run { target c++17 } }
3 #include <experimental/synchronized_value>
4 #include <testsuite_hooks.h>
5 #include <string>
7 using std::experimental::synchronized_value;
9 synchronized_value<std::string> s;
11 std::string read_value(){
12 return apply([](auto& x){return x;},s);
15 void set_value(std::string const& new_val){
16 apply([&](auto& x){ x = new_val; }, s);
19 void
20 test_single()
22 set_value("new value");
23 VERIFY( read_value() == "new value" );
26 void
27 test_multi()
29 synchronized_value<int> a(1), b(2), c(3);
30 int sum = apply([](auto&... ints) { return (ints++ + ...); }, a, b, c);
31 VERIFY( sum == 6 );
32 auto get = [](int& i) { return i; };
33 VERIFY( apply(get, a) == 2 );
34 VERIFY( apply(get, b) == 3 );
35 VERIFY( apply(get, c) == 4 );
38 int main()
40 test_single();
41 test_multi();