⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dimension.hpp

📁 矩阵运算源码最新版本
💻 HPP
字号:
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef MTL_DIMENSIONS_INCLUDE#define MTL_DIMENSIONS_INCLUDE#include <iostream>#include <boost/mpl/if.hpp>#include <boost/utility/enable_if.hpp>namespace mtl {// dimension is a type for declaring matrix dimensions // num_rows() and num_cols() return the number or rows and columns// is_static says whether it is declared at compile time or not// Compile time versionnamespace fixed{    template <std::size_t Rows, std::size_t Cols>    struct dimensions    {	typedef std::size_t  size_type;        static size_type const Num_Rows= Rows;        static size_type const Num_Cols= Cols;	size_type num_rows() const 	{	    return Rows;	}	size_type num_cols() const 	{	    return Cols;	}	// to check whether it is static	static bool const is_static= true;	typedef dimensions<Cols, Rows> transposed_type;	transposed_type transpose() const 	{ 	    return transposed_type(); 	}    };    template <std::size_t R, std::size_t C>    inline std::ostream& operator<< (std::ostream& stream, dimensions<R, C>)     {	return stream << R << 'x' << C;     }} // namespace fixednamespace non_fixed{    struct dimensions    {	typedef std::size_t  size_type;	// some simple constructors	dimensions() : r(0), c(0) {}	dimensions(size_type r, size_type c) : r(r), c(c) {}	dimensions(const dimensions& x) : r(x.r), c(x.c) {}	dimensions& operator=(const dimensions& x) 	{	    r= x.r; c= x.c; return *this; 	}	size_type num_rows() const 	{	    return r;	}	size_type num_cols() const {	    return c;	}	typedef dimensions transposed_type;	transposed_type transpose() 	{ 	    return transposed_type(c, r); 	}	static bool const is_static= false;    protected:	size_type r, c;    };    inline std::ostream& operator<< (std::ostream& stream, dimensions d)     {	return stream << d.num_rows() << 'x' << d.num_cols();     }} // namespace non_fixed#if 0template <std::size_t Rows = 0, std::size_t Cols = 0>struct dimensions  : public boost::mpl::if_c<	 Rows != 0 && Cols != 0       , struct fixed::dimensions       , struct non_fixed::dimensions       >::type{    dimensions(std::size_t r, std::size_t c, 	       typename boost::enable_if_c<Rows == 0 || Cols == 0>::type* = 0)	: non_fixed::dimensions(r, c) {}};#endif} // namespace mtl#endif // MTL_DIMENSIONS_INCLUDE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -