std::experi...nd_last_set(3)
π NAME π
okay so this is the std::experi...nd_last_set(3) page from the C++ Standard Libary section, and the name line is literally:
std::experimental::find_first_set,std::experimental::find_last_set - std::experimental::find_first_set,std::experimental::find_last_set
yes bestie, it's one page for two functions: std::experimental::find_first_set and std::experimental::find_last_set. iconic. π
β¨ Synopsis β¨
Defined in header <experimental/simd>
template< class T, class Abi > (1) (parallelism TS v2)
int find_first_set( const simd_mask<T, Abi>& k );
template< class T, class Abi > (2) (parallelism TS v2)
int find_last_set( const simd_mask<T, Abi>& k );
So:
find_first_setreturns the lowest indexiwherek[i]istrue. π«Άfind_last_setreturns the greatest indexiwherek[i]istrue. π
β οΈ warning bestie: the behavior is undefined ifany_of(k)isfalse. fr fr, do not play with that. π
π Parameters π
kβ thesimd_maskto apply the reduction to. that's the whole parameter list, no cap. π
π Return value π
an int in the range [0, simd_size_v<T, Abi>). slay. β¨
π¦ Example π¦
// Run this code
#include <cstddef>
#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;
template<typename Abi>
int find(stdx::simd_mask<Abi> const& v)
{
if (stdx::any_of(v))
return find_first_set(v);
return -1;
}
int main()
{
stdx::simd_mask<short> a{0};
a[2] = a[a.size() - 2] = 1;
for (std::size_t i = 0; i < a.size(); ++i)
std::cout << a[i] << ' ';
std::cout << '\n';
std::cout << "find_first_set: " << stdx::find_first_set(a) << '\n';
std::cout << "find_last_set: " << stdx::find_last_set(a) << '\n';
std::cout << "find: " << find(a) << '\n';
a[2] = 0;
std::cout << "find: " << find(a) << '\n';
a[a.size() - 2] = 0;
std::cout << "find: " << find(a) << '\n';
}
π Possible output π
0 0 1 0 0 0 1 0
find_first_set: 2
find_last_set: 6
find: 2
find: 6
find: -1
okay bye bestie π«Ά this page is from http://cppreference.com, version/date 2024.06.10, and the manual name is std::experi...nd_last_set(3). now go find those set bits, periodt. πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms