29 Numerics library [numerics]

29.10 Data-parallel types [simd]

29.10.9 Class template basic_mask [simd.mask.class]

29.10.9.1 Class template basic_mask overview [simd.mask.overview]

namespace std::simd { template<size_t Bytes, class Abi> class basic_mask { public: using value_type = bool; using abi_type = Abi; using iterator = simd-iterator<basic_mask>; using const_iterator = simd-iterator<const basic_mask>; constexpr iterator begin() noexcept { return {*this, 0}; } constexpr const_iterator begin() const noexcept { return {*this, 0}; } constexpr const_iterator cbegin() const noexcept { return {*this, 0}; } constexpr default_sentinel_t end() const noexcept { return {}; } constexpr default_sentinel_t cend() const noexcept { return {}; } static constexpr integral_constant<simd-size-type, simd-size-v<integer-from<Bytes>, Abi>> size {}; constexpr basic_mask() noexcept = default; // [simd.mask.ctor], basic_mask constructors constexpr explicit basic_mask(value_type) noexcept; template<size_t UBytes, class UAbi> constexpr explicit basic_mask(const basic_mask<UBytes, UAbi>&) noexcept; template<class G> constexpr explicit basic_mask(G&& gen) noexcept; constexpr basic_mask(const bitset<size()>& b) noexcept; constexpr explicit basic_mask(unsigned_integral auto val) noexcept; // [simd.mask.subscr], basic_mask subscript operators constexpr value_type operator[](simd-size-type) const; template<simd-integral I> constexpr resize_t<I::size(), basic_mask> operator[](const I& indices) const; // [simd.mask.unary], basic_mask unary operators constexpr basic_mask operator!() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator+() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator-() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator~() const noexcept; // [simd.mask.conv], basic_mask conversion operators template<class U, class A> constexpr explicit(sizeof(U) != Bytes) operator basic_vec<U, A>() const noexcept; // [simd.mask.namedconv], basic_mask named type convertors constexpr bitset<size()> to_bitset() const noexcept; constexpr unsigned long long to_ullong() const; // [simd.mask.binary], basic_mask binary operators friend constexpr basic_mask operator&&(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator||(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator&(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator|(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator^(const basic_mask&, const basic_mask&) noexcept; // [simd.mask.cassign], basic_mask compound assignment friend constexpr basic_mask& operator&=(basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask& operator|=(basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask& operator^=(basic_mask&, const basic_mask&) noexcept; // [simd.mask.comparison], basic_mask comparisons friend constexpr basic_mask operator==(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator!=(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator>=(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator<=(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator>(const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask operator<(const basic_mask&, const basic_mask&) noexcept; // [simd.mask.cond], basic_mask exposition only conditional operators friend constexpr basic_mask simd-select-impl( // exposition only const basic_mask&, const basic_mask&, const basic_mask&) noexcept; friend constexpr basic_mask simd-select-impl( // exposition only const basic_mask&, same_as<bool> auto, same_as<bool> auto) noexcept; template<class T0, class T1> friend constexpr vec<see below, size()> simd-select-impl(const basic_mask&, const T0&, const T1&) noexcept; // exposition only }; }
Every specialization of basic_mask is a complete type.
The specialization of basic_mask<Bytes, Abi> is:
  • disabled, if there is no vectorizable type T such that Bytes is equal to sizeof(T),
  • otherwise, enabled, if there exists a vectorizable type T and a value N in the range [1, 64] such that Bytes is equal to sizeof(T) and Abi is deduce-abi-t<T, N>,
  • otherwise, it is implementation-defined if such a specialization is enabled.
If basic_mask<Bytes, Abi> is disabled, the specialization has a deleted default constructor, deleted destructor, deleted copy constructor, and deleted copy assignment.
In addition only the value_type and abi_type members are present.
If basic_mask<Bytes, Abi> is enabled, basic_mask<Bytes, Abi> is trivially copyable.
Recommended practice: Implementations should support implicit conversions between specializations of basic_mask and appropriate implementation-defined types.
[Note 1: 
Appropriate types are non-standard vector types which are available in the implementation.
— end note]

29.10.9.2 basic_mask constructors [simd.mask.ctor]

constexpr explicit basic_mask(value_type x) noexcept;
Effects: Initializes each element with x.
template<size_t UBytes, class UAbi> constexpr explicit basic_mask(const basic_mask<UBytes, UAbi>& x) noexcept;
Constraints: basic_mask<UBytes, UAbi>​::​size() == size() is true.
Effects: Initializes the element with x[i] for all i in the range of [0, size()).
template<class G> constexpr explicit basic_mask(G&& gen);
Constraints: The expression gen(integral_constant<simd-size-type, i>()) is well-formed and its type is bool for all i in the range of [0, size()).
Effects: Initializes the element with gen(integral_constant<simd-size-type, i>()) for all i in the range of [0, size()).
Remarks: gen is invoked exactly once for each i, in increasing order of i.
constexpr basic_mask(const bitset<size()>& b) noexcept;
Effects: Initializes the element with b[i] for all i in the range [0, size()).
constexpr explicit basic_mask(unsigned_integral auto val) noexcept;
Effects: Initializes the first M elements to the corresponding bit values in val, where M is the smaller of size() and the number of bits in the value representation ([basic.types.general]) of the type of val.
If M is less than size(), the remaining elements are initialized to zero.

29.10.9.3 basic_mask subscript operator [simd.mask.subscr]

constexpr value_type operator[](simd-size-type i) const;
Preconditions: i >= 0 && i < size() is true.
Returns: The value of the element.
Throws: Nothing.
template<simd-integral I> constexpr resize_t<I::size(), basic_mask> operator[](const I& indices) const;
Effects: Equivalent to: return permute(*this, indices);

29.10.9.4 basic_mask unary operators [simd.mask.unary]

constexpr basic_mask operator!() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator+() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator-() const noexcept; constexpr basic_vec<integer-from<Bytes>, Abi> operator~() const noexcept;
Let op be the operator.
Returns: A data-parallel object where the element is initialized to the results of applying op to operator[](i) for all i in the range of [0, size()).

29.10.9.5 basic_mask conversion operators [simd.mask.conv]

template<class U, class A> constexpr explicit(sizeof(U) != Bytes) operator basic_vec<U, A>() const noexcept;
Constraints: simd-size-v<U, A> == simd-size-v<T, Abi>.
Returns: A data-parallel object where the element is initialized to static_cast<U>(operator[](i)).

29.10.9.6 basic_mask named conversion operators [simd.mask.namedconv]

constexpr bitset<size()> to_bitset() const noexcept;
Returns: A bitset<size()> object where the element is initialized to operator[](i) for all i in the range [0, size()).
constexpr unsigned long long to_ullong() const;
Let N be the width of unsigned long long.
Preconditions:
  • size() <= N is true, or
  • for all i in the range [N, size()), operator[](i) returns false.
Returns: The integral value corresponding to the bits in *this.
Throws: Nothing.