summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/26_numerics/valarray/83860.cc
blob: 7f38b4af05a0f7582fc89c97aaed9048829d3a9a (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (C) 2018-2019 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 <valarray>
#include <testsuite_hooks.h>

const std::valarray<int> v{
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
};

bool
all_of(const std::valarray<bool>& vals)
{
  for (bool b : vals)
    if (!b)
      return false;
  return true;
}

void
test01()
{
  // PR libstdc++/83860
  const std::valarray<int> va(v), vb(v), vc(v);
  auto sum = va + vb + vc;
  std::valarray<int> vsum = sum;
  VERIFY( all_of( vsum == (3 * v) ) );
}

void
test02()
{
  auto neg = -(-v);
  std::valarray<int> vneg = neg;
  VERIFY( all_of( vneg == v ) );
}

void
test03()
{
  const std::valarray<int> va(v), vb(v);
  auto diff = va + -vb;
  std::valarray<int> vdiff = diff;
  VERIFY( all_of( vdiff == (va - vb) ) );
}

void
test04()
{
  const std::valarray<int> va(v), vb(v);
  auto sum = -va + -vb;
  std::valarray<int> vsum = sum;
  VERIFY( all_of( vsum == (-2 * v) ) );
}

void
test05()
{
  const std::valarray<int> va(v), vb(v);
  auto sum = -(-va + -vb);
  std::valarray<int> vsum = sum;
  VERIFY( all_of( vsum == (2 * v) ) );
}

void
test06()
{
  auto prod = 3 * +v * 2;
  std::valarray<int> vprod = prod;
  VERIFY( all_of( vprod == (6 * v) ) );
}

void
test07()
{
  const std::valarray<int> va(v), vb(v);
  auto valfun = [](int i) { return i; };
  auto reffun = [](const int& i) { return i; };
  auto sum = (va.apply(valfun) + vb.apply(reffun));
  std::valarray<int> vsum = sum;
  VERIFY( all_of( vsum == (va + vb) ) );
}

int
main()
{
  test01();
  test02();
  test03();
  test04();
  test05();
  test06();
  test07();
}