| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Parallel exceptions | ||||
| Additional execution policies | ||||
| Algorithms | ||||
| Task blocks | ||||
| Data-parallel vectors | ||||
Defined in header <experimental/simd> | ||
template<class T,class Abi> simd<T, Abi> | (parallelism TS v2) | |
Contents |
| v | - | the elements to clamp |
| lo, hi | - | the boundaries to clampv to |
The result of element-wise application ofstd::clamp(v[i], lo[i], hi[i]) for alli ∈[0, size()).
#include <cstddef>#include <cstdint>#include <experimental/simd>#include <iomanip>#include <iostream>namespace stdx= std::experimental; void println(auto rem,autoconst v){std::cout<< rem<<": ";for(std::size_t i=0; i!= v.size();++i)std::cout<<std::setw(4)<< v[i]<<' ';std::cout<<'\n';} int main(){ stdx::fixed_size_simd<int,8> a{[](int i){staticconstexprauto c={-129,-128,-1,0,42,127,128,255};return c.begin()[i];}}; println("a", a); stdx::fixed_size_simd<int,8> lo1{INT8_MIN}; stdx::fixed_size_simd<int,8> hi1{INT8_MAX};constauto b= stdx::clamp(a, lo1, hi1); println("b", b); stdx::fixed_size_simd<int,8> lo2{0}; stdx::fixed_size_simd<int,8> hi2{UINT8_MAX};constauto c= stdx::clamp(a, lo2, hi2); println("c", c);}
Output:
a: -129 -128 -1 0 42 127 128 255 b: -128 -128 -1 0 42 127 127 127 c: 0 0 0 0 42 127 128 255
(C++17) | clamps a value between a pair of boundary values (function template)[edit] |