maybe.hpp
来自「矩阵运算源码最新版本」· HPP 代码 · 共 59 行
HPP
59 行
// 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_MAYBE_INCLUDE#define MTL_MAYBE_INCLUDE#include <iostream>namespace mtl { namespace utilities {template <class Value>struct maybe : public std::pair<Value, bool> { typedef std::pair<Value, bool> base; typedef maybe<Value> self; maybe(bool b) : base(Value(), b) {} maybe(Value v) : base(v, true) {} maybe(Value v, bool b) : base(v, b) {} maybe(base b) : base(b) {} operator bool() const { return this->second; } operator Value() const { return this->first; } bool has_value() const { return this->second; } Value value() const { return this->first; }};template <class Value>inline std::ostream& operator<< (std::ostream& os, maybe<Value> const& m){ return os << '(' << m.value() << ", " << (m ? "true" : "false") << ')';}} // namespace utilitiesusing utilities::maybe; } // namespace mtl#endif // MTL_MAYBE_INCLUDE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?