本文整理汇总了C++中initializer_list类的典型用法代码示例。如果您正苦于以下问题:C++ initializer_list类的具体用法?C++ initializer_list怎么用?C++ initializer_list使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了initializer_list类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: addCell
// // //Add cell to the list
void addCell(initializer_list<int_8 > l) {
if (l.size() == 2) {
listCell.emplace_back( shared_ptr<Cell > (new Line(l)) );
// //listCell.emplace_back(shared_ptr<Cell > (new Line(tmp)) );
} else if (l.size() == 3) {
// //listCell.emplace_back(shared_ptr<Cell > (new Tri(tmp)) );
} else if (l.size() == 4) {
listCell.emplace_back( shared_ptr<Cell > (new Quad(l)) );
} else if (l.size() == 8) {
//listCell.emplace_back( shared_ptr<Cell > (new Hexa(tmp)) );
} else {
cout << "Cell type not understood!"<<endl;
exit(1);
}
nCellSize += l.size() + 1;
auto c = *(listCell.rbegin());
c->id = listCell.size()-1;
c->grid = this;
c->assignCelltoNode();
for (auto v: listVar) {
if (v->loc == 0) {
v->data.push_back(0);
v->data.uncompress();
}
}
c->masterx.resize(levelHighBound[0]+1, false);
c->mastery.resize(levelHighBound[1]+1, false);
c->masterz.resize(levelHighBound[2]+1, false);
}
开发者ID:uzgoren,项目名称:girdap,代码行数:31,代码来源:Grid.hpp
示例2: makeSum
int makeSum(initializer_list<int> lst)
{
int total = 0;
for(auto iter = lst.begin(); iter!=lst.end(); ++iter)
total += (*iter);
return total;
}
开发者ID:cloudrain21,项目名称:study_room,代码行数:7,代码来源:initialize_list1.cpp
示例3: PointSequence
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);
}
开发者ID:EmuxEvans,项目名称:Woody-Ye-s-Code-Share,代码行数:7,代码来源:InitializerListCtor.cpp
示例4: Animation
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];
}
开发者ID:danijar,项目名称:console-game,代码行数:7,代码来源:entities.cpp
示例5: 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;
}
}
开发者ID:vishaladu,项目名称:cppprojects,代码行数:25,代码来源:class-09.cpp
示例6: invalid_argument
EvenSequenceStr::EvenSequenceStr(initializer_list<string> args)
{
if (args.size() % 2 != 0)
throw invalid_argument(" initializer_list should contain even number of elements!");
sSequence.reserve(args.size());
//for (auto value : args) sSequence.push_back(value);
sSequence.insert(cend(sSequence), cbegin(args), cend(args)); // alternate to the above for loop
}
开发者ID:georgiosdoumas,项目名称:ProgrammingCplusplus-,代码行数:8,代码来源:EvenSequence.cpp
示例7: Function
Function(const char* name, const char* returns, initializer_list<char*> takes, const char* description) : Type(name) {
this->takes = new char*[takes.size() + 1];
int index = 0;
for (auto i : takes) { this->takes[index++] = i; }
this->takes[takes.size()] = 0;
this->returns = returns;
this->description = description;
}
开发者ID:nestharus,项目名称:Notepad---vJASS,代码行数:8,代码来源:function.hpp
示例8: 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;
}
开发者ID:QSaman,项目名称:CppExamples,代码行数:8,代码来源:Vector1.cpp
示例9:
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;
}
开发者ID:LvChong,项目名称:My_Primer,代码行数:8,代码来源:StrVec.cpp
示例10: 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;
}
开发者ID:xiweihuang,项目名称:Primer,代码行数:8,代码来源:initializer.cpp
示例11: summation
int summation(initializer_list<int> val)
{
int ret = 0;
for (auto beg = val.begin(); beg != val.end(); ++beg)
{
ret += *beg;
}
return ret;
}
开发者ID:wkvictor,项目名称:Cpp-Prime-5th-ed,代码行数:9,代码来源:Ex6_27.cpp
示例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());
}
开发者ID:serrainoalessio,项目名称:tre,代码行数:9,代码来源:image.cpp
示例13: 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;
}
开发者ID:3A9C,项目名称:ITstep,代码行数:10,代码来源:Vector.cpp
示例14: CreateWorld
//local->world
Matrix44 TransformHelper::CreateWorld(initializer_list<Matrix44> matrixOrder)
{ //스케일, 자전, 이동, 공전, 부모 순으로 넣으면 된다.
Matrix44 matWorld;
for( auto iter = matrixOrder.begin(); iter != matrixOrder.end(); ++iter )
{
matWorld = (*iter) * matWorld;
}
return matWorld;
}
开发者ID:kihx,项目名称:rasterizer,代码行数:11,代码来源:CoolD_Transform.cpp
示例15: owner
Army::Army(Player* owner, initializer_list<Unit*> units) : owner(owner), isPatrol(false), position(Position(-1, -1, ARCANUS)), route(nullptr)
{
owner->add(this);
for (auto u : units)
add(u);
if (units.begin() != units.end())
updateMovementType();
}
开发者ID:Jakz,项目名称:openmom,代码行数:10,代码来源:Army.cpp
示例16:
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];
}
}
开发者ID:ninaolo,项目名称:hypercube,代码行数:10,代码来源:kth_cprog_template_container.hpp
示例17: subscriptCheck
void subscriptCheck(initializer_list<int> lst)
{
cout<<"initializer_list subscript check\n";
// for(int i = 0; i < lst.size(); ++i)
// cout<<lst[i]<<'\n'; // error
const int* p = lst.begin();
for(int i = 0; i < lst.size(); ++i)
cout<<p[i]<<'\n';
}
开发者ID:Hades210,项目名称:year17,代码行数:11,代码来源:initializer_listCheck.cpp
示例18: logic_error
RunTimeContainer::RunTimeContainer(initializer_list<RunTime> initializer) {
if (ZoneHandler::getZoneCount() != initializer.size()) {
throw logic_error("ZoneHandler::getZoneCount() != initializer.size()");
}
container.reserve(ZoneHandler::getZoneCount());
for (size_t i = 0; i < ZoneHandler::getZoneCount(); ++i) {
shared_ptr<RunTime> runTime(new RunTime(*next(initializer.begin(), i)));
container.push_back(make_pair(i, runTime));
}
}
开发者ID:gyengep,项目名称:irrigation,代码行数:11,代码来源:RunTimeContainer.cpp
示例19: Polynomial
template<typename T> Polynomial(initializer_list<T> list){
coeffs.resize(list.size());
int i=list.size()-1;
for(T t:list){
coeffs[i]=t;
i--;
}
reduce();
}
开发者ID:OOliOO,项目名称:AlgGeom,代码行数:11,代码来源:polynomial.hpp
示例20:
StateTreeNode::StateTreeNode(
initializer_list<double> center,
double halfSize,
int maxDepth
) :
numSpacePartitions(pow(2, center.size()))
{
for(unsigned int n = 0; n < center.size(); n++)
this->center.push_back(*(center.begin() + n));
this->halfSize = halfSize;
this->maxDepth = maxDepth;
}
开发者ID:dafer45,项目名称:TBTK,代码行数:13,代码来源:StateTreeNode.cpp
注:本文中的initializer_list类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论