Namespaces
Variants

std::simd::basic_vec<T,Abi>::operator++, std::simd::basic_vec<T,Abi>::operator++(int), std::simd::basic_vec<T,Abi>::operator--, std::simd::basic_vec<T,Abi>::operator--(int)

From cppreference.com
 
 
 
Data-parallel types (SIMD)
 
 
constexpr basic_vec& operator++() noexcept;
(1) (since C++26)
constexpr basic_vec operator++( int ) noexcept;
(2) (since C++26)
constexpr basic_vec& operator--() noexcept;
(3) (since C++26)
constexpr basic_vec operator--( int ) noexcept;
(4) (since C++26)

Increments or decrements every element by one, as if by applying the same operator to each element of type T.

1,3) Pre-increment and pre-decrement. These overloads participate in overload resolution only if T supports ++a or --a, respectively.
2,4) Post-increment and post-decrement. These overloads participate in overload resolution only if T supports a++ or a--, respectively.

In particular, these operators are not available if T is a specialization of std::complex. If the operation overflows a signed integer element, the behavior is undefined, and unsigned integer elements wrap around.

Return value

1,3) *this
2,4) A copy of *this made before the modification.

Notes

GCC on x86-64 compiles increment and decrement of integer elements to a single vector subtraction or addition of -1, such as vpsubd or vpaddd for int, with the -1 elements created by vpcmpeqd without a memory access, and of float elements to vaddps with a broadcast constant 1.0f or -1.0f. These examples are GCC's output for x86-64 with AVX2.

Example

#include <cstdint>
#include <print>
#include <simd>
#include <utility>

int main()
{
    std::simd::vec<int, 4> v([](int i) { return i * 10; });
    std::println("v   = {}", v);
    std::println("++v = {}", ++v);

    auto old = v++;
    std::println("old = {}, v = {}", old, v);
    std::println("--v = {}", --v);

    std::simd::vec<std::uint8_t, 4> u = std::cw<255>;
    ++u; // unsigned elements wrap around
    std::println("u   = {}", u);

    std::simd::vec<float, 4> f = 0.5f;
    f--;
    std::println("f   = {}", f);
}

Output:

v   = [0, 10, 20, 30]
++v = [1, 11, 21, 31]
old = [1, 11, 21, 31], v = [2, 12, 22, 32]
--v = [1, 11, 21, 31]
u   = [0, 0, 0, 0]
f   = [-0.5, -0.5, -0.5, -0.5]

See also

element-wise compound assignment
(function) [edit]
element-wise unary operators
(public member function) [edit]