/*============================================================================= Copyright (c) 2011-2017 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_COMPLEX_STREAM_OPERATORS_HPP #define SPROUT_COMPLEX_STREAM_OPERATORS_HPP #include #include #include #include namespace sprout { template inline SPROUT_NON_CONSTEXPR std::basic_istream& operator>>(std::basic_istream& lhs, sprout::complex& rhs) { T re, im; Char ch; lhs >> ch; if (ch == '(') { lhs >> re >> ch; if (ch == ',') { lhs >> im >> ch; if (ch == ')') { rhs = sprout::complex(re, im); } else { lhs.setstate(std::ios_base::failbit); } } else if (ch == ')') { rhs = re; } else { lhs.setstate(std::ios_base::failbit); } } else { lhs.putback(ch); lhs >> re; rhs = re; } return lhs; } template inline SPROUT_NON_CONSTEXPR std::basic_ostream& operator<<(std::basic_ostream& lhs, sprout::complex const& rhs) { return lhs << '(' << rhs.real() << ',' << rhs.imag() << ')'; } } // namespace sprout #endif // #ifndef SPROUT_COMPLEX_STREAM_OPERATORS_HPP