Operator expansions for std::vector<T>
Abstract
Operator definitions on SSTD. These definitions are read by #include <sstd/sstd.hpp>
.
SSTD における演算子の定義.#include <sstd/sstd.hpp>
により定義が読み込まれる.
Header file
namespace sstd_stdVecEx{
// operators for mathematics
SSTD_DEF_stdVecEx_defInNamespace (add ); // +
SSTD_DEF_stdVecEx_defInNamespace_eq(add_eq); // +=
SSTD_DEF_stdVecEx_defInNamespace (sub ); // -
SSTD_DEF_stdVecEx_defInNamespace_eq(sub_eq); // -=
SSTD_DEF_stdVecEx_defInNamespace (mul ); // *
SSTD_DEF_stdVecEx_defInNamespace_eq(mul_eq); // *=
SSTD_DEF_stdVecEx_defInNamespace (div ); // /
SSTD_DEF_stdVecEx_defInNamespace_eq(div_eq); // /=
SSTD_DEF_stdVecEx_defInNamespace (mod ); // %
SSTD_DEF_stdVecEx_defInNamespace_eq(mod_eq); // %=
SSTD_DEF_stdVecEx_defInNamespace (pow ); // ^
SSTD_DEF_stdVecEx_defInNamespace_eq(pow_eq); // ^=
// operators for std::vector
SSTD_DEF_stdVecEx_defInNamespace (push_front ); // >>
SSTD_DEF_stdVecEx_defInNamespace_eq(push_front_eq); // >>=
SSTD_DEF_stdVecEx_defInNamespace (push_back ); // <<
SSTD_DEF_stdVecEx_defInNamespace_eq(push_back_eq ); // <<=
}
Usage
Ope. * and *=
vector × scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v = {1, 2, 3}; sstd::printn( v * 2 ); v *= 3; sstd::printn( v ); }
- Execution result
v * 2 = [2 4 6] v = [3 6 9]
vector × vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v1 = {1, 2, 3}; std::vector<int> v2 = {2, 3, 4}; sstd::printn( v1 * v2 ); v1 *= v2; sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 * v2 = [2 6 12] v1 = [2 6 12] v2 = [2 3 4]
any depth vector × scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::vector<std::vector<int>>> v = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}; sstd::printn( v * 2 ); v *= 3; sstd::printn( v ); }
- Execution result
v * 2 = [[[2 4] [6 8]] [[10 12] [14 16]]] v = [[[3 6] [9 12]] [[15 18] [21 24]]]
any depth vector × vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<std::vector<std::vector<int>>> v1 = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}; std::vector<std::vector<std::vector<int>>> v2 = {{{9, 10}, {11, 12}}, {{13, 14}, {15, 16}}}; sstd::printn( v1 * v2 ); v1 *= v2; sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 * v2 = [[[9 20] [33 48]] [[65 84] [105 128]]] v1 = [[[9 20] [33 48]] [[65 84] [105 128]]] v2 = [[[9 10] [11 12]] [[13 14] [15 16]]]
Linking <<
vector << scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v = {1, 2, 3}; int s = 4; sstd::printn( v << s ); sstd::printn( v ); sstd::printn( s ); }
- Execution result
v << s = [1 2 3 4] v = [1 2 3] s = 4
vector << vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v1 = {1, 2, 3}; std::vector<int> v2 = {4, 5, 6}; sstd::printn( v1 << v2 ); sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 << v2 = [1 2 3 4 5 6] v1 = [1 2 3] v2 = [4 5 6]
push_back()
vector <<= scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v; v <<= 1; // same as a "v.push_back(1);" v <<= 2; // same as a "v.push_back(2);" v <<= 3; // same as a "v.push_back(3);" sstd::printn( v ); }
- Execution result
v = [1 2 3]
vector <<= vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v1 = {1, 2, 3}; std::vector<int> v2 = {4, 5, 6}; v1 <<= v2; sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 = [1 2 3 4 5 6] v2 = [4 5 6]
Linking >>
vector >> scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v = {1, 2, 3}; int s = 0; sstd::printn( v >> s ); sstd::printn( v ); sstd::printn( s ); }
- Execution result
v >> s = [0 1 2 3] v = [1 2 3] s = 0
vector >> vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v1 = {1, 2, 3}; std::vector<int> v2 = {-2, -1, 0}; sstd::printn( v1 >> v2 ); sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 >> v2 = [-2 -1 0 1 2 3] v1 = [1 2 3] v2 = [-2 -1 0]
push_front()
vector >>= scalar
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v = {1, 2, 3}; v >>= 0; sstd::printn( v ); }
- Execution result
v = [0 1 2 3]
vector >>= vector
- main.cpp
#include <sstd/sstd.hpp> int main(){ std::vector<int> v1 = {1, 2, 3}; std::vector<int> v2 = {-2, -1, 0}; v1 >>= v2; sstd::printn( v1 ); sstd::printn( v2 ); }
- Execution result
v1 = [-2 -1 0 1 2 3] v2 = [-2 -1 0]
Implementation
- Source: header only
- Header: sstd/src/container/vector/stdVector_expansion.hpp
- Test: test/src_test/container/vector/stdVector_expansion.cpp