std::valarray<T>:: operator+,-,~,!
From cppreference.net
|
valarray
<
T
>
operator
+
(
)
const
;
|
(1) | |
|
valarray
<
T
>
operator
-
(
)
const
;
|
(2) | |
|
valarray
<
T
>
operator~
(
)
const
;
|
(3) | |
|
valarray
<
bool
>
operator
!
(
)
const
;
|
(4) | |
숫자 배열의 각 요소에 단항 연산자를 적용합니다.
목차 |
매개변수
(없음)
반환값
* this 에 있는 값들에 해당 연산자를 적용하여 얻은 값들을 요소로 가지는 숫자 배열.
예외
구현 정의 예외를 던질 수 있습니다.
참고 사항
각 연산자는 다음 요구 사항이 충족되는 경우에만 인스턴스화될 수 있습니다:
-
-
표시된 연산자를 타입
T에 적용할 수 있습니다. -
결과 값은 명확하게
T(1-3) 또는 bool (4)로 변환될 수 있습니다.
-
표시된 연산자를 타입
이 함수는 반환 타입이 std::valarray 와 다르게 구현될 수 있습니다. 이 경우, 대체 타입은 다음과 같은 속성을 가집니다:
-
- const 멤버 함수 전부가 std::valarray 에 제공됩니다.
- std::valarray , std::slice_array , std::gslice_array , std::mask_array 및 std::indirect_array 은 대체 타입으로부터 생성될 수 있습니다.
- const std:: valarray < T > & 을 받는 모든 함수에 대해 begin() 과 end() 를 제외하고 (C++11부터) , 동일한 함수들이 대체 타입들을 받도록 추가되어야 합니다;
- 두 개의 const std:: valarray < T > & 인자를 받는 모든 함수에 대해, const std:: valarray < T > & 과 대체 타입들의 모든 조합을 받는 동일한 함수들이 추가되어야 합니다.
- 반환 타입은 가장 깊이 중첩된 인자 타입에 대해 두 수준 이상의 템플릿 중첩을 추가하지 않습니다.
예제
이 코드 실행
#include <iostream> #include <string_view> #include <valarray> template<typename T> void print(std::string_view const note, std::valarray<T> const vala, // by-value, see Notes above std::string_view const term = "\n") { std::cout << note << std::boolalpha << std::showpos; for (T const element : vala) std::cout << '\t' << element; std::cout << term; } int main() { std::valarray<int> x{1, 2, 3, 4}; print<int>("x: ", x); print<int>("+x: ", +x); print<int>("+ + x: ", + + x); print<int>("-x: ", -x); print<int>("- - x: ", - - x, "\n\n"); std::valarray<short> y{0, 1, -1, 0x7fff}; print<short>("y: ", y); print<short>("~y: ", ~y); print<short>("~~y: ", ~~y, "\n\n"); std::valarray<bool> z{true, false}; print<bool>("z: ", z); print<bool>("!z: ", !z); print<bool>("!!z: ", !!z); }
가능한 출력:
x: +1 +2 +3 +4 +x: +1 +2 +3 +4 + + x: +1 +2 +3 +4 -x: -1 -2 -3 -4 - - x: +1 +2 +3 +4 y: +0 +1 -1 +32767 ~y: -1 -2 +0 -32768 ~~y: +0 +1 -1 +32767 z: true false !z: false true !!z: true false
참고 항목
|
복합 할당 연산자를 valarray의 각 요소에 적용
(public member function) |
|
|
두 valarray의 각 요소에, 또는 valarray와 값에 이항 연산자를 적용
(function template) |