Daily bump.
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / net / execution_context / use_service.cc
blob1cf51369cf9f27fc60b8ad23c1991d20958e50c1
1 // Copyright (C) 2015-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++14 } }
19 // { dg-additional-options "-pthread" { target pthread } }
21 #include <experimental/executor>
22 #include <testsuite_hooks.h>
24 using std::experimental::net::execution_context;
25 using std::experimental::net::use_service;
27 struct service1 : execution_context::service
29 using key_type = service1;
30 service1(execution_context& c) : service(c) { }
31 void shutdown() noexcept { }
34 struct key2 : execution_context::service
36 key2(execution_context& c) : service(c) { }
39 struct service2 : key2
41 using key_type = key2;
42 service2(execution_context& c) : key2(c) { }
43 void shutdown() noexcept { }
46 struct service3 : service1
48 using service1::service1;
51 struct service4 : service2
53 using service2::service2;
56 void
57 test01()
59 execution_context ctx;
60 service1& svc1 = use_service<service1>(ctx);
61 service1& svc1a = use_service<service1>(ctx);
62 VERIFY( &svc1a == &svc1 );
64 key2& svc2 = use_service<service2>(ctx);
65 key2& svc2a = use_service<service2>(ctx);
66 VERIFY( &svc2a == &svc2 );
68 service1& svc3 = use_service<service3>(ctx);
69 VERIFY( &svc3 == &svc1 );
71 key2& svc4 = use_service<service4>(ctx);
72 VERIFY( &svc4 == &svc2 );
74 // TODO test02() function that puts derived types in first, then tests base comes out
77 int
78 main()
80 test01();