本文整理汇总了C++中initializer_list::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ initializer_list::begin方法的具体用法?C++ initializer_list::begin怎么用?C++ initializer_list::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类initializer_list
的用法示例。
在下文中一共展示了initializer_list::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
UnitCell::UnitCell(
initializer_list<initializer_list<double>> latticeVectors,
bool isOwner
) :
StateSet(isOwner)
{
unsigned int numCoordinates = latticeVectors.begin()->size();
for(unsigned int n = 1; n < latticeVectors.size(); n++){
TBTKAssert(
(latticeVectors.begin()+n)->size() == numCoordinates,
"UnitCell::UnitCell()",
"Incmopatible coordinate dimensions. The first lattice"
<< "vector has " << numCoordinates << " coordinates, "
<< "while lattice vector " << n << " has "
<< (latticeVectors.begin()+n)->size()
<< " coordinates.",
""
);
}
for(unsigned int n = 0; n < latticeVectors.size(); n++){
this->latticeVectors.push_back(vector<double>());
const initializer_list<double> *latticeVector = (latticeVectors.begin() + n);
for(unsigned int c = 0; c < latticeVector->size(); c++)
this->latticeVectors.at(n).push_back(*(latticeVector->begin()+c));
}
}
示例2: setTransformations
void Transformation::setTransformations(int _num, initializer_list<string> st)
{
numOfOperations = _num;
left.insert(left.begin(), st.begin(), st.begin() + _num);
right.insert(right.begin(), st.begin() + _num, st.end());
for (size_t i = 0; i < numOfOperations; ++i)
{
if (right[i] == ".")
{
right[i] = "";
}
}
}
示例3: Entity
EntityList::EntityList( initializer_list<Entity*> e )
: Entity((*(e.begin()))->getEntityType()->getCore())
{
for (const auto &x : e) {
internalAdd(x);
}
}
示例4: range_error
SparseVector::SparseVector(long size, long default_val, initializer_list<pair<long,long> > list)
{
if (size < 0) {
throw range_error("SparseVector size cannot be negative.");
} else {
fixed_size_ = size;
unset_val_ = default_val;
}
long count = 0;
for (auto i = list.begin(); i != list.end(); i++) {
if (i->first < (fixed_size_ - 1) && i->first >= 0) {
if (i->second != unset_val_) {
data_[i->first] = data_[i->second];
}
} else {
throw range_error("Cannot set value at an index greater than the size - 1 or less than 0.");
}
++count;
}
}
示例5: invalid_argument
PointSequence(initializer_list<double> args)
{
if (args.size() % 2 != 0)
throw invalid_argument("initializer_list should contain even number of elements.");
for (auto iter = args.begin(); iter != args.end(); ++iter)
mVecPoints.push_back(*iter);
}
示例6: makeSum
int makeSum(initializer_list<int> lst)
{
int total = 0;
for(auto iter = lst.begin(); iter!=lst.end(); ++iter)
total += (*iter);
return total;
}
示例7: speed
Animation(int x, int y, initializer_list<char> chars, int speed = 5) : speed(speed), frame(1), counter(0)
{
Collision = true;
Pos.Set(x, y);
for(auto i = chars.begin(); i != chars.end(); ++i) frames.push_back(*i);
Visual = frames[0];
}
示例8:
StrVec::StrVec(initializer_list<string> il)
{
reallocate(il.size());
auto p = begin_iter;
for (auto beg = il.begin(); beg != il.end(); ++beg)
alloc.construct(p++, *beg);
end_iter = p;
}
示例9: cal_sum
int cal_sum(initializer_list<int> &list)
{
int sum = 0;
for (auto i = list.begin(); i != list.end(); ++i) {
sum += *i;
}
return sum;
}
示例10: Vector
Vector(initializer_list<T> list) : size{list.size()}
{
cout << "initializer list constructor" << endl;
int i = 0;
a.reset(new T[size]);
for (auto iter = list.begin(); iter != list.end(); ++iter, ++i)
a.get()[i] = *iter;
}
示例11: range_equal
bool range_equal(vector<size_t> v, initializer_list<size_t> e) {
if(!std::equal(v.begin(), v.end(), e.begin())) {
for(auto x : v) cerr << x << ",";
cerr << " == ";
for(auto x : e) cerr << x << ",";
cerr << endl;
return false;
} else return true;
}
示例12:
Image::Image(int _rows,int _cols,initializer_list<float> _data):rows(_rows),cols(_cols){
this->allocate();
#if IMAGE_SAFE == 1
assert(_data.size() == rows*cols);
#endif
std::copy(_data.begin(), _data.end(), data.get());
}
示例13: summation
int summation(initializer_list<int> val)
{
int ret = 0;
for (auto beg = val.begin(); beg != val.end(); ++beg)
{
ret += *beg;
}
return ret;
}
示例14: sizeof
Vector::Vector(initializer_list<double> args)
{
auto it = args.begin();
element_count = args.size();
memory_size = element_count * 2;
vector = (double*)malloc(memory_size * sizeof(double));
int i;
for (it, i = 0; it != args.end(); it++, i++)
vector[i] = *it;
}
示例15:
Vector<T>::Vector(const initializer_list<T>& l) {
static_assert(is_move_assignable<T>::value, "Type is not move assignable.");
static_assert(is_move_constructible<T>::value, "Type is not move constructible."); // Can be constructed fr rvalue
vectorsize = l.size();
heap_size = l.size();
array = new T[vectorsize];
for (int i = 0; i < vectorsize; ++i) {
array[i] = l.begin()[i];
}
}