summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/21_strings/basic_string/cons/wchar_t/8.cc
blob: 0fee57826229818c78f0b96dfc300a280b2a0059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (C) 2016-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-do run { target c++11 } }

#include <string>
#include <testsuite_hooks.h>

template<typename... Args>
std::size_t
construct(Args&&... args)
{
  return std::wstring( std::forward<Args>(args)... ).length();
}

void
test01()
{
  using string = std::wstring;
  using list = std::initializer_list<string::value_type>;

  const std::wstring lvalue = L"lvalue";
  std::allocator<char> alloc;

  // test all valid combinations of arguments:
  VERIFY( construct( ) == 0 );
  VERIFY( construct( alloc ) == 0 );
  VERIFY( construct( lvalue ) == 6 );
  VERIFY( construct( string{L"rvalue"} ) == 6 );
  VERIFY( construct( lvalue, 2 ) == 4 );
  VERIFY( construct( lvalue, 2, alloc ) == 4 );
  VERIFY( construct( lvalue, 2, 3 ) == 3 );
  VERIFY( construct( lvalue, 2, 3, alloc ) == 3 );
  VERIFY( construct( L"C string", 4 ) == 4 );
  VERIFY( construct( L"C string", 4, alloc ) == 4 );
  VERIFY( construct( L"C string" ) == 8 );
  VERIFY( construct( L"C string and alloc", alloc ) == 18 );
  VERIFY( construct( 5, L' ' ) == 5 );
  VERIFY( construct( 5, L' ', alloc ) == 5 );
  VERIFY( construct( lvalue.begin(), lvalue.end() ) == 6 );
  VERIFY( construct( lvalue.begin(), lvalue.end(), alloc ) == 6 );
  VERIFY( construct( list{ L'l' , L'i' , L's', L't' } ) == 4 );
  VERIFY( construct( list{ L'l', L'i', L's', L't' }, alloc ) == 4 );
#if _GLIBCXX_USE_CXX11_ABI
  VERIFY( construct( lvalue, alloc ) == 6 );
  VERIFY( construct( string{L"rvalue"}, alloc ) == 6 );
#endif
}

int
main()
{
  test01();
}