5#ifndef MADNESS_ARRAY_OF_BOOLS_H
6#define MADNESS_ARRAY_OF_BOOLS_H
18template <std::
size_t N>
27 template <std::
size_t NN = N,
typename = std::enable_if_t<NN==0>>
34 template <
typename ... Bools,
typename = std::enable_if_t<
sizeof...(Bools)+1==
N>>
38 bool any()
const {
return std::accumulate(this->begin(), this->end(),
false, std::logical_or{}); }
44 bool all()
const {
return std::accumulate(this->begin(), this->end(),
false, std::logical_and{}); }
47 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
48 array_of_
bools<C> front() const {
49 array_of_
bools<C> result;
50 std::copy(this->begin(), this->begin()+
C, result.begin());
57 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
58 array_of_
bools& assign_front(const array_of_
bools<C>& a) {
59 std::copy(a.begin(), a.end(), this->begin());
66 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
67 array_of_
bools and_front(const array_of_
bools<C>& a) const {
68 array_of_
bools result;
69 const auto it = std::transform(a.begin(), a.end(), this->begin(), result.begin(),
71 std::copy(this->begin() +
C, this->end(), it);
78 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
79 array_of_
bools or_front(const array_of_
bools<C>& a) const {
80 array_of_
bools result;
81 const auto it = std::transform(a.begin(), a.end(), this->begin(), result.begin(),
83 std::copy(this->begin() +
C, this->end(), it);
88 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
89 array_of_
bools<C> back() const {
90 array_of_
bools<C> result;
91 std::copy(this->begin() + (
N -
C), this->end(), result.begin());
98 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
99 array_of_
bools& assign_back(const array_of_
bools<C>& a) {
100 std::copy(a.begin(), a.end(), this->begin() + (
N -
C));
107 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
108 array_of_
bools and_back(const array_of_
bools<C>& a) const {
109 array_of_
bools result;
111 std::copy(this->begin(), this->begin() + (
N -
C), result.begin());
112 std::transform(
a.begin(),
a.end(), this->begin() + (
N -
C), it,
120 template <std::
size_t C,
typename = std::enable_if_t<C <= N>>
121 array_of_
bools or_back(const array_of_
bools<C>& a) const {
122 array_of_
bools result;
124 std::copy(this->begin(), this->begin() + (
N -
C), result.begin());
125 std::transform(
a.begin(),
a.end(), this->begin() + (
N -
C), it,
132 std::transform(
a.begin(),
a.end(),
b.begin(), result.begin(), std::logical_and{});
137 std::transform(
a.begin(),
a.end(),
b.begin(), result.begin(), std::logical_or{});
142 std::transform(
a.begin(),
a.end(),
b.begin(), result.begin(), [](
auto b1,
auto b2) {
149 std::transform(
a.begin(),
a.end(), result.begin(), std::logical_not{});
155 std::transform(
a.begin(),
a.end(), result.begin(), [
b](
auto a_v) {
165 std::transform(
a.begin(),
a.end(), result.begin(), [
b](
auto a_v) {
175 std::transform(
a.begin(),
a.end(), result.begin(), [
b](
auto a_v) {
187 template <std::
size_t NN = N,
typename = std::enable_if_t<NN!=0>>
190 template <std::
size_t NN>
194static_assert(std::is_same_v<array_of_bools<1>::value_type,
bool>);
196static_assert(std::is_same_v<
decltype(array_of_bools<2>{
true,
false}[0]),
bool&>);
197static_assert(std::is_same_v<
decltype(array_of_bools<0>{} && array_of_bools<0>{}), array_of_bools<0>>);
198static_assert(std::is_same_v<
decltype(array_of_bools<0>{} || array_of_bools<0>{}), array_of_bools<0>>);
199static_assert(std::is_same_v<
decltype(array_of_bools<0>{} ^ array_of_bools<0>{}), array_of_bools<0>>);
200static_assert(std::is_same_v<
decltype(!array_of_bools<0>{}), array_of_bools<0>>);
201static_assert(std::is_same_v<
decltype(array_of_bools<0>{} &&
true), array_of_bools<0>>);
202static_assert(std::is_same_v<
decltype(
true && array_of_bools<0>{}), array_of_bools<0>>);
203static_assert(std::is_same_v<
decltype(array_of_bools<0>{} ||
true), array_of_bools<0>>);
204static_assert(std::is_same_v<
decltype(
true || array_of_bools<0>{}), array_of_bools<0>>);
205static_assert(std::is_same_v<
decltype(array_of_bools<0>{} ^
true), array_of_bools<0>>);
206static_assert(std::is_same_v<
decltype(
true ^ array_of_bools<0>{}), array_of_bools<0>>);
Definition test_ar.cc:170
syntactic sugar for std::array<bool, N>
Definition array_of_bools.h:19
array_of_bools(bool v, Bools... vs)
constructs an array filled with {v, vs...}
Definition array_of_bools.h:35
bool any() const
Definition array_of_bools.h:38
friend class array_of_bools
Definition array_of_bools.h:191
friend array_of_bools< N > operator!(const array_of_bools< N > &a)
Definition array_of_bools.h:147
array_of_bools()
default ctor public only for N==0
Definition array_of_bools.h:28
std::array< bool, N > base_type
Definition array_of_bools.h:21
array_of_bools(nonempty_default_ctor_tag={})
Definition array_of_bools.h:188
array_of_bools(bool v)
constructs an array filled with v
Definition array_of_bools.h:31
const auto & as_array() const
Definition array_of_bools.h:23
friend array_of_bools< N > operator&&(const array_of_bools< N > &a, bool b)
Definition array_of_bools.h:153
auto & as_array()
Definition array_of_bools.h:24
friend array_of_bools< N > operator^(const array_of_bools< N > &a, const array_of_bools< N > &b)
Definition array_of_bools.h:140
friend array_of_bools< N > operator||(bool b, const array_of_bools< N > &a)
Definition array_of_bools.h:170
friend array_of_bools< N > operator^(const array_of_bools< N > &a, bool b)
Definition array_of_bools.h:173
bool all() const
Definition array_of_bools.h:44
friend array_of_bools< N > operator&&(const array_of_bools< N > &a, const array_of_bools< N > &b)
Definition array_of_bools.h:130
friend array_of_bools< N > operator&&(bool b, const array_of_bools< N > &a)
Definition array_of_bools.h:160
friend array_of_bools< N > operator||(const array_of_bools< N > &a, const array_of_bools< N > &b)
Definition array_of_bools.h:135
friend array_of_bools< N > operator||(const array_of_bools< N > &a, bool b)
Definition array_of_bools.h:163
bool none() const
Definition array_of_bools.h:41
friend array_of_bools< N > operator^(bool b, const array_of_bools< N > &a)
Definition array_of_bools.h:180
static const double v
Definition hatom_sf_dirac.cc:20
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
Definition array_of_bools.h:186
#define N
Definition testconv.cc:37