示例#1
0
文件: Grid.hpp 项目: uzgoren/girdap
  // // //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); 
  }
示例#2
0
文件: UnitCell.cpp 项目: dafer45/TBTK
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));
	}
}
示例#3
0
		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;
		}
EvenSequenceNum::EvenSequenceNum(initializer_list<double> args)
{
  if (args.size() % 2 != 0)
    throw invalid_argument(" initializer_list should contain even number of elements!");
  mSequence.reserve(args.size());
  for (auto value : args)  mSequence.push_back(value);
   //mSequence.insert(cend(mSequence), cbegin(args), cend(args)); // alternate to the above for loop
}
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
}
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];
    }
}
示例#7
0
    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();
    }
示例#8
0
/**
 * @brief calc_back_project : encapsulate calcHist, provide friendly api, all of the parameters meaning are same as
 * the calcHist
 */
void calc_histogram(initializer_list<Mat> images, OutputArray output, initializer_list<int> channels,
                    initializer_list<int> hist_sizes, initializer_list<float[2]> ranges,
InputArray mask, bool uniform, bool accumulate)
{
    size_t const sizes = ranges.size();
    vector<float const*> d_ranges(sizes);
    for(size_t i = 0; i != sizes; ++i){
        d_ranges[i] = *(begin(ranges) + i);
    }

    calcHist(begin(images), images.size(), begin(channels), mask, output,
                 channels.size(), begin(hist_sizes), &d_ranges[0], uniform ,accumulate);
}
示例#9
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;
}
    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);
	}
    }
示例#11
0
  Vector(initializer_list<_Tp> __li, const _Allocator& __a = _Allocator()) :
		alloc(__a), __size(0), __capacity(0) {
      buffer = alloc.allocate(__li.size());
      for (auto _list : __li)
        push_back(_list);
      __capacity = __size;
    }
示例#12
0
文件: main.cpp 项目: CCJY/coliru
void foo(initializer_list<int> x)
{
    //static_assert(x.size()==2, "dd"); // decomment for bestemmie
    int arr[x.size()];
     arr[0] = 10;
    cout << arr[0] << endl;
}
示例#13
0
static const pair<vector<string>, unordered_map<string, int> > computeHashes(initializer_list<const char *> names)
{
	pair <vector<string>, unordered_map<string, int> > result;

	result.first.reserve(names.size());
	for (const char *name : names) {
		result.first.emplace_back(name);
	}

	result.second.reserve(names.size());
	for(typeof(names.size()) i = 0; i < names.size(); i++) {
		result.second.emplace(result.first[i], i);
	}

	return result;
}
示例#14
0
Model::Model(initializer_list<string> meshNames,
			 const string& diffuseName,
			 const string& specularName,
		 	 const string& ambientName,
		 	 const string& normalName,
		 	 float uniformScale,
			 float translateY,
			 float rotateY) {
	// Load meshes
	meshes.resize(meshNames.size());
	int i = 0;
	for (auto name : meshNames) {
		meshes[i].load(name);
		i += 1;
	}
	// Load textures
	diffuse.loadImage(diffuseName);
	specular.loadImage(specularName);
	if (useNormalMapping) {
		ambient.loadImage(ambientName);
		normal.loadImage(normalName);
		// Generate tangent values for normal mapping
		transform(begin(meshes), end(meshes), back_inserter(tangents), Model::generateTangents);
	}
	// Save scaling and translation values
	this->uniformScale = uniformScale;
	this->translateY = translateY;
	this->rotateY = rotateY;
}
	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);
	}
示例#16
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;
 }
示例#17
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;
}
static void expect_contents(const quotient_filter<T, H, B> &c,
                            const initializer_list<size_t> hash_list) {
  ASSERT_TRUE(hash_list.size() > 0) << "For empty filters use expect_empty()";

  EXPECT_FALSE(c.empty());
  EXPECT_EQ(hash_list.size(), c.size());
  EXPECT_EQ(ptrdiff_t(hash_list.size()), distance(c.begin(), c.end()));
  EXPECT_FLOAT_EQ(float(c.size()) / c.slot_count(), c.load_factor());
  EXPECT_LE(c.load_factor(), c.max_load_factor());

  auto it = c.begin();
  for (const size_t hash : hash_list) {
    ASSERT_TRUE(it != c.end());
    EXPECT_EQ(hash, *it++);
  }
  EXPECT_TRUE(it == c.end());
}
示例#19
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;
}
示例#20
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());
}
示例#21
0
文件: main.cpp 项目: CCJY/coliru
auto make_sparse_vector(initializer_list<pair<size_t, T>> init, const T& defval = T())
{
    if (init.size()==0) return vector<T>{};
    vector<T> out(max_element(begin(init), end(init))->first + 1, defval);
    for (const auto& p : init)
    {
        out[p.first] = p.second;
    }
    return out;
}
示例#22
0
文件: Vector.cpp 项目: 3A9C/ITstep
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;
}
示例#23
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';
}
示例#24
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));
	}
}
示例#25
0
void i2c::write( initializer_list< uint8_t > data )
{
    setAddress();

    auto res = ::write(mDevice, begin( data ), data.size() );
    if( res < 0 )
    {
        ostringstream os;
        os << "unable to write (" << res << "): "  << strerror( errno );
        throw runtime_error{ move( os.str() ) };
    }
}
示例#26
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;
}
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++;
    }

}
示例#28
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;
    }
示例#29
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];
	}
示例#30
0
Vector<T,I>::Vector(initializer_list<T> list) {
	cout << "initializer list Constructor" << endl;
	static_assert(is_move_constructible<T>::value 
			&& is_move_assignable<T>::value,
			"The type is not movable or copyable");
	msize = list.size();
	capacity_ = 2*msize;
	pArray_ = new T[capacity_];
	init = 1;
	int j = 0;
	for(T i : list) {
		pArray_[j] = i;
		j++;
	}
}