c_cpp cell_templates.cpp

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp cell_templates.cpp相关的知识,希望对你有一定的参考价值。

#include <iostream>


/* Acts as a base index class for indexing a collection of cells.
* Child classes can be made to derive an absolute placement in an array of cells.
* This can work for 1, 2, or even 3 dimensional grids.
* Example, if grid is 2D, 4 X 4 cells, the absolute index can
* be derived from (x,y) x * 4 + y
*/

class CellIndex
{
public:
	/* @brief: Method that derives absolute index from multiple variables
	*          or values.
	*  @example: width = 3, length = 3, (1, 2) -> 1 * 3 + 2 -> 5 in array
	*  @note: Needs to be overloaded in child classes.
	*/
	virtual size_t absolute() const { return 0; }
};


/*  @breif:  Zero-indexed 1D child class of Cell Index, supports integral types
*   @detail: For an (x) neighborhood, 0 is the first element, x - 1 i s the last.
*/
template<class IndexType = size_t>
class OneDimensionIndex : public CellIndex
{
private:
	IndexType _x;
public:
	OneDimensionIndex(IndexType i = 0): _x(i)
	{}
	~OneDimensionIndex()
	{}

	size_t absolute() const
	{
		return _x;
	}
};

template<class CellType, unsigned dimensions>
class CellSequence
{

};


int main(int argc, char const *argv[])
{
	OneDimensionIndex<> foo;
	std::cout << foo.absolute() << " that is foo absolute\n";
	return 0;
}

以上是关于c_cpp cell_templates.cpp的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 200.岛屿数量

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *