Пример #1
0
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
0
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
0
EntityList::EntityList( initializer_list<Entity*> e )
	: Entity((*(e.begin()))->getEntityType()->getCore())
{
	for (const auto &x : e) {
		internalAdd(x);
	}
}
Пример #4
0
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;
    }
}
	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
0
int makeSum(initializer_list<int> lst)
{
    int total = 0;
    for(auto iter = lst.begin(); iter!=lst.end(); ++iter)
	total += (*iter);
    return total;
}
Пример #7
0
	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
0
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
0
int cal_sum(initializer_list<int> &list)
{
	int sum = 0;
	for (auto i = list.begin(); i != list.end(); ++i) {
		sum += *i;
	}
	return sum;
}
Пример #10
0
 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
0
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
0
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
0
int summation(initializer_list<int> val)
{
	int ret = 0;
	for (auto beg = val.begin(); beg != val.end(); ++beg)
	{
		ret += *beg;
	}
	return ret;
} 
Пример #14
0
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;
}
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];
    }
}
Пример #16
0
	//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;
	}
Пример #17
0
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();
}
Пример #18
0
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));
	}
}
Пример #19
0
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';
}
Пример #20
0
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;
}
Пример #21
0
StrVec::StrVec(const initializer_list<string> &slist)
{
	size_t len = slist.size();
	auto newdata = alloc.allocate(len);
	auto dest = newdata;
	auto beg = slist.begin();
	while(beg != slist.end()){
		alloc.construct(dest++, std::move(*beg++));
	}
	
	elements = newdata;
	first_free = cap = dest;
}
Пример #22
0
    Foo(initializer_list<Foo> list){
        cout << "initializer "<< list.size() << "-list: \n";

        size_t index = 0;
        for (const Foo &it : list){
            cout << "\titem " << index++ << " ";
            it.printValues();
        }

        cout << endl << "\tcopying values from first element of init_list.\n\t";
        *this = *list.begin();
        cout << endl;
    }
Пример #23
0
    PointSequence(initializer_list<double> args)
    {
	cout << "size : " << args.size() << endl;
	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);
	}
    }
Пример #24
0
string Strings::gs( initializer_list< string > args ) noexcept{
  string base;
  ostringstream ans;
  auto bp = strings.find( *args.begin() );
  if( bp == strings.end() )
    base = *args.begin();
  else
    base = bp->second;
	
  auto b = base.begin();
  auto e = base.end();
  size_t argn = 0;
  while( b != e ){
    if( *b == '%' ){
      ++b;
      if( b != e && !isdigit( *b ) ){
	ans << *b++;
	continue;
      }
      while( b != e && isdigit( *b ) ){
	argn *= 10;
	argn += ( *b++ - '0' );
      }
      if( argn && argn < args.size() ){
	auto argsb = args.begin();
	while( argn-- )
	  ++argsb;
	ans << *argsb;
	argn = 0;
      }	
    }else
      ans << *b++;
  }
    
  return ans.str();
}
Пример #25
0
	/// Construct a matrix with the data given in two nested
	/// initializer_list's
	dense_matrix( const initializer_list<initializer_list<value_type>> &l )
	{
		// Compute sizes
		const initializer_list<value_type>* prow = l.begin();
		int	I = l.size();
		int	J = prow[0].size();
		for( int i = 1; i < I; i++ )
			assert( J == (int)prow[i].size() );

		// Fill the matrix
		this->resize(I,J);
		for( int i = 0; i < I; i++ )
			for( int j = 0; j < J; j++ )
				(*this)(i,j) = prow[i].begin()[j];
	}
Пример #26
0
UInteger make_integer_impl(UInteger native, initializer_list<unsigned char> bytes)
{
	decltype(bytes)::const_iterator i = bytes.begin();
	if ( bytes.size() > sizeof(native) ) {
		i += bytes.size() - sizeof(native);
	}
	if ( sizeof(native) > 1 ) {
		for ( ; i != bytes.end(); ++i ) {
			native <<= CHAR_BIT;
			native |= *i;
		}
	}
	else {
		native = *i;
	}
	return native;
}
Пример #27
0
	/// Construct a matrix by concatenating the sub-matrices given in two
	/// nested initializer_list's
	dense_matrix( const initializer_list<initializer_list<dense_matrix<value_type>>> &list )
	{
		// Compute sizes
		const initializer_list<dense_matrix<value_type>>* prow = list.begin();
		int	Ib = list.size();
		int I  = 0;
		int J  = 0;
		for( int ib = 0; ib < Ib; ib++ ) {										// For each block row
			const dense_matrix<value_type>* pblock = prow[ib].begin();				// Pointer to a block matrix in this row
			int Il = pblock[0].size1();											// Number of rows in this block row
			I     += Il;														// Update the total number of rows
			int Jb = prow[ib].size();											// Number of block columns in this row
			int Jl = 0;															// Total number of columns in this block row
			for( int jb = 0; jb < Jb; jb++ ) {
				assert( (int)pblock[jb].size1() == Il );
				Jl += pblock[jb].size2();
			}

			// Check that all block rows have the same number of columns
			if( ib == 0 )
				J = Jl;
			else
				assert( J == Jl );
		}

		// Fill the matrix
		this->resize(I,J);
		int cursor_I = 0;
		for( int ib = 0; ib < Ib; ib++ ) {
			int Jb = prow[ib].size();											// Number of block columns in this row
			const dense_matrix<value_type>* pblock = prow[ib].begin();				// Pointer to a block matrix in this row
			int cursor_J = 0;
			int Il = pblock[0].size1();
			for( int jb = 0; jb < Jb; jb++ ) {
				int Jl = pblock[jb].size2();
				auto rI = range( cursor_I, cursor_I + Il );
				auto rJ = range( cursor_J, cursor_J + Jl );
				ublas::matrix_range<dense_matrix<value_type>>(*this,rI,rJ)
						= pblock[jb];
				cursor_J += Jl;
			}
			cursor_I += Il;
		}
	}
Пример #28
0
TabelarnaFunkcija::TabelarnaFunkcija(initializer_list<pair<double, double>> lista)

{
    for(auto it = lista.begin(); it != lista.end(); it++) {
        for(auto it2 = it + 1; it2 != lista.end(); it2++) {
            if(it2->first == it->first) {
                throw domain_error("Ponavljanje istog x elementa.");
            }
        }
    }

    parovi = new pair<double, double>[lista.size()];
    max_broj_parova = lista.size();
    broj_dodanih_parova = lista.size();

    int cntr = 0;
    for(auto i : lista) {
        parovi[cntr] = i;
        cntr++;
    }

}
Пример #29
0
			//----------
			void Strip::setCellSizes(const initializer_list<int> & cellSizes) {
				this->programmaticCellSizes = vector<int>(cellSizes.begin(), cellSizes.end());
				this->resetUserCellSizes();
			}
	// 2016.04.18 add
	array(const initializer_list<T>& args)
	{ uninitialized_copy(args.begin(), args.end(), elem); }