| 1 |
// Copyright (C) 2015-2025 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. |
| 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 |
|
| 18 |
// { dg-do compile { target c++14 } } |
| 19 |
|
| 20 |
#include <experimental/buffer> |
| 21 |
|
| 22 |
using namespace std::experimental::net; |
| 23 |
using std::vector; |
| 24 |
using std::string; |
| 25 |
using std::char_traits; |
| 26 |
using std::allocator; |
| 27 |
|
| 28 |
template<typename T> |
| 29 |
struct Seq { |
| 30 |
struct Buf { |
| 31 |
operator T() const { return {}; } |
| 32 |
}; |
| 33 |
|
| 34 |
Buf* begin() const { return nullptr; } |
| 35 |
Buf* end() const { return nullptr; } |
| 36 |
}; |
| 37 |
|
| 38 |
static_assert( is_mutable_buffer_sequence<mutable_buffer>::value, |
| 39 |
"mutable_buffer is a mutable buffer sequence" ); |
| 40 |
static_assert( is_mutable_buffer_sequence<const mutable_buffer>::value, |
| 41 |
"const mutable_buffer is a mutable buffer sequence" ); |
| 42 |
static_assert( is_mutable_buffer_sequence<vector<mutable_buffer>>::value, |
| 43 |
"vector<mutable_buffer> is a mutable buffer sequence" ); |
| 44 |
static_assert( is_mutable_buffer_sequence<const vector<mutable_buffer>>::value, |
| 45 |
"const vector<mutable_buffer> is a mutable buffer sequence" ); |
| 46 |
static_assert( is_mutable_buffer_sequence<Seq<mutable_buffer>>::value, |
| 47 |
"Seq<mutable_buffer> is a mutable buffer sequence" ); |
| 48 |
static_assert( is_mutable_buffer_sequence<const Seq<mutable_buffer>>::value, |
| 49 |
"const Seq<mutable_buffer> is a mutable buffer sequence" ); |
| 50 |
static_assert( is_mutable_buffer_sequence<Seq<const mutable_buffer>>::value, |
| 51 |
"Seq<const mutable_buffer> is a mutable buffer sequence" ); |
| 52 |
static_assert( ! is_mutable_buffer_sequence<const_buffer>::value, |
| 53 |
"const_buffer is not a mutable buffer sequence" ); |
| 54 |
static_assert( ! is_mutable_buffer_sequence<vector<const_buffer>>::value, |
| 55 |
"vector<const_buffer> is not a mutable buffer sequence" ); |
| 56 |
static_assert( ! is_mutable_buffer_sequence<Seq<const_buffer>>::value, |
| 57 |
"Seq<const_buffer> is not a mutable buffer sequence" ); |
| 58 |
|
| 59 |
static_assert( is_const_buffer_sequence<const_buffer>::value, |
| 60 |
"const_buffer is a const buffer sequence" ); |
| 61 |
static_assert( is_const_buffer_sequence<const const_buffer>::value, |
| 62 |
"const const_buffer is a const buffer sequence" ); |
| 63 |
static_assert( is_const_buffer_sequence<vector<const_buffer>>::value, |
| 64 |
"vector<const_buffer> is a const buffer sequence" ); |
| 65 |
static_assert( is_const_buffer_sequence<const vector<const_buffer>>::value, |
| 66 |
"const vector<const_buffer> is a const buffer sequence" ); |
| 67 |
static_assert( is_const_buffer_sequence<Seq<const_buffer>>::value, |
| 68 |
"Seq<const_buffer> is a const buffer sequence" ); |
| 69 |
static_assert( is_const_buffer_sequence<const Seq<const_buffer>>::value, |
| 70 |
"const Seq<const_buffer> is a const buffer sequence" ); |
| 71 |
static_assert( is_const_buffer_sequence<Seq<const const_buffer>>::value, |
| 72 |
"Seq<const const_buffer> is a const buffer sequence" ); |
| 73 |
static_assert( is_const_buffer_sequence<mutable_buffer>::value, |
| 74 |
"mutable_buffer is a const buffer sequence" ); |
| 75 |
static_assert( is_const_buffer_sequence<const mutable_buffer>::value, |
| 76 |
"const mutable_buffer is a const buffer sequence" ); |
| 77 |
static_assert( is_const_buffer_sequence<vector<mutable_buffer>>::value, |
| 78 |
"vector<mutable_buffer> is a const buffer sequence" ); |
| 79 |
static_assert( is_const_buffer_sequence<const vector<mutable_buffer>>::value, |
| 80 |
"const vector<mutable_buffer> is a const buffer sequence" ); |
| 81 |
|
| 82 |
// Buf -> mutable_buffer -> const_buffer needs two user-defined conversions: |
| 83 |
static_assert( ! is_const_buffer_sequence<Seq<mutable_buffer>>::value, |
| 84 |
"Seq<mutable_buffer> is not a const buffer sequence" ); |
| 85 |
|
| 86 |
static_assert( is_dynamic_buffer< |
| 87 |
dynamic_vector_buffer<int, allocator<int>> |
| 88 |
>::value, "dynamic_vector_buffer is a dynamic buffer" ); |
| 89 |
static_assert( is_dynamic_buffer< |
| 90 |
dynamic_string_buffer<char, char_traits<char>, allocator<int>> |
| 91 |
>::value, "dynamic_string_buffer is a dynamic buffer" ); |
| 92 |
static_assert( ! is_dynamic_buffer<vector<int>>::value, |
| 93 |
"vector is not a dynamic buffer" ); |
| 94 |
static_assert( ! is_dynamic_buffer<string>::value, |
| 95 |
"string is not a dynamic buffer" ); |