]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/net/execution_context/use_service.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / net / execution_context / use_service.cc
CommitLineData
8d9254fc 1// Copyright (C) 2015-2020 Free Software Foundation, Inc.
e5989e71
JW
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.
8
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.
13
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/>.
17
7e8b87e9 18// { dg-do run { target c++14 } }
e5989e71
JW
19
20#include <experimental/executor>
21#include <testsuite_hooks.h>
22
23using std::experimental::net::execution_context;
24using std::experimental::net::use_service;
25
26struct service1 : execution_context::service
27{
28 using key_type = service1;
29 service1(execution_context& c) : service(c) { }
30 void shutdown() noexcept { }
31};
32
33struct key2 : execution_context::service
34{
35 key2(execution_context& c) : service(c) { }
36};
37
38struct service2 : key2
39{
40 using key_type = key2;
41 service2(execution_context& c) : key2(c) { }
42 void shutdown() noexcept { }
43};
44
45struct service3 : service1
46{
47 using service1::service1;
48};
49
50struct service4 : service2
51{
52 using service2::service2;
53};
54
55void
56test01()
57{
58 execution_context ctx;
59 service1& svc1 = use_service<service1>(ctx);
60 service1& svc1a = use_service<service1>(ctx);
61 VERIFY( &svc1a == &svc1 );
62
63 key2& svc2 = use_service<service2>(ctx);
64 key2& svc2a = use_service<service2>(ctx);
65 VERIFY( &svc2a == &svc2 );
66
67 service1& svc3 = use_service<service3>(ctx);
68 VERIFY( &svc3 == &svc1 );
69
70 key2& svc4 = use_service<service4>(ctx);
71 VERIFY( &svc4 == &svc2 );
72
73 // TODO test02() function that puts derived types in first, then tests base comes out
74}
75
76int
77main()
78{
79 test01();
80}