-
Notifications
You must be signed in to change notification settings - Fork 0
Variable
Architector edited this page Apr 18, 2019
·
13 revisions
This container is a buffer abstraction represents a regular variable or class object.
ecl::var<T>();
ecl::var<T>(const& T value);
ecl::var<T>(ecl::ACCESS);
ecl::var<T>(const T& value, ecl::ACCESS);
Example:
ecl::var<int> a; // not-initialized
ecl::var<int> b = 5; // b = 5
ecl::var<float> c(7.0f, ecl::ACCESS::READ); // c = 7.0f (read-only)
To get /set value:
const T& getValue() const;
void setValue(const T& value);
Also you can use overloaded operators!
- Increment / dicrement:
var++;
var--;
Example:
ecl::var<int> a = 3;
a++; // 4
a--; // 3
- Equality:
var = const T&;
var += const T&;
var -= const T&;
var *= const T&;
var /= const T&;
Example:
ecl::var<int> a = 3;
ecl::var<int> b = 5;
a += 2; // a = 5
a -= b; // a = 0
b = 3;
- Friend:
var<T>& = var + const T&;
var<T>& = var - const T&;
var<T>& = var * const T&;
var<T>& = var / const T&;
Example:
ecl::var<int> a = 3;
ecl::var<int> b = 5;
b = a * 3; // b = 9
- Casting:
operator T&();
Note: So, if any function takes a reference or const reference, or value of T
you may pass var<T>
instead!
Example:
void foo(int a){
std::cout << a << std::endl; // 5
}
ecl::var<int> a = 5;
foo(a);
- Out to stream:
ostream& << const var<T>&;
Example:
ecl::var<double> a = 6.0;
std::cout << a; // 6.0
You can use (copy / move) (constructors / operator=):
- Copy:
var<T>(const var<T>&);
var = const var<T>&;
Example:
ecl::var<int> a;
ecl::var<int> b = 5;
ecl::var<int> c = b; // copy (create buffer and copy value on host)
a = b; // copy
- Move:
var<T>(var<T>&&);
var = std::move(var<T>&&);
Example:
ecl::var<int> a = 2;
ecl::var<int> b = std::move(a); // now 'a' is empty, 'b' grabs all data
ecl::var<int> c = 4;
c = std::move(b); // now 'b' is empty, 'c' grabs all data
Note: All these operation done only on host. To know how to work with devices, look at Computer
section.
Twitter: Architector
e-mail: olegsajaxov@yandex.ru
Wiki
Getting started
API