2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2011-12-23 11:59:33 +00:00
|
|
|
#ifndef TESTSPR_PRINT_HPP
|
|
|
|
#define TESTSPR_PRINT_HPP
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
2012-02-25 02:51:23 +00:00
|
|
|
#include <bitset>
|
2014-02-19 23:04:36 +00:00
|
|
|
#include <utility>
|
2011-12-23 11:59:33 +00:00
|
|
|
#include <iostream>
|
2014-02-19 23:04:36 +00:00
|
|
|
#include <iomanip>
|
2014-07-22 00:33:13 +00:00
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/container.hpp>
|
2014-02-19 23:04:36 +00:00
|
|
|
#include <sprout/detail/io/ios_state.hpp>
|
2012-06-16 06:35:10 +00:00
|
|
|
#include <testspr/typeinfo.hpp>
|
2011-12-23 11:59:33 +00:00
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
//
|
|
|
|
// print
|
|
|
|
//
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print() {}
|
2014-02-19 23:04:36 +00:00
|
|
|
template<typename Head, typename... Tail>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print(Head const& head, Tail const&... tail) {
|
2014-02-19 23:04:36 +00:00
|
|
|
std::cout << head;
|
|
|
|
testspr::print(tail...);
|
2012-02-25 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// print_ln
|
|
|
|
//
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_ln() {
|
2013-08-03 09:14:22 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
2014-02-19 23:04:36 +00:00
|
|
|
template<typename... Args>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_ln(Args const&... args) {
|
2014-02-19 23:04:36 +00:00
|
|
|
sprout::detail::io::ios_all_saver saver(std::cout);
|
|
|
|
testspr::print(args...);
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// print_tokens
|
|
|
|
//
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_tokens() {
|
2014-02-19 23:04:36 +00:00
|
|
|
testspr::print_ln();
|
2012-02-25 02:51:23 +00:00
|
|
|
}
|
2013-08-03 09:14:22 +00:00
|
|
|
template<typename Head, typename... Tail>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_tokens(Head const& head, Tail const&... tail) {
|
2014-02-19 23:04:36 +00:00
|
|
|
sprout::detail::io::ios_all_saver saver(std::cout);
|
|
|
|
testspr::print(head, ' ');
|
|
|
|
testspr::print_tokens(tail...);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// print_quotes
|
|
|
|
//
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_quotes() {
|
2014-02-19 23:04:36 +00:00
|
|
|
testspr::print_ln();
|
|
|
|
}
|
|
|
|
template<typename Head, typename... Tail>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_quotes(Head const& head, Tail const&... tail) {
|
2014-02-19 23:04:36 +00:00
|
|
|
sprout::detail::io::ios_all_saver saver(std::cout);
|
|
|
|
testspr::print('\"', head, "\" ");
|
|
|
|
testspr::print_quotes(tail...);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// print_range
|
|
|
|
//
|
|
|
|
template<typename InputIterator>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_range(InputIterator first, InputIterator last) {
|
2014-02-19 23:04:36 +00:00
|
|
|
sprout::detail::io::ios_all_saver saver(std::cout);
|
|
|
|
for (; first != last; ++first) {
|
|
|
|
std::cout << *first << ' ';
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
template<typename InputRange>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_range(InputRange const& range) {
|
2014-02-19 23:04:36 +00:00
|
|
|
testspr::print_range(sprout::begin(range), sprout::end(range));
|
2013-08-03 09:14:22 +00:00
|
|
|
}
|
2012-02-25 02:51:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// print_bits
|
|
|
|
//
|
|
|
|
template<typename T>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_bits(T const& t) {
|
2012-02-25 02:51:23 +00:00
|
|
|
testspr::print_ln(std::bitset<sizeof(T) * 8>(t).template to_string<char>());
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 06:35:10 +00:00
|
|
|
//
|
|
|
|
// print_typename
|
|
|
|
//
|
|
|
|
template<typename T>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_typename() {
|
2012-06-16 06:35:10 +00:00
|
|
|
testspr::print_ln(testspr::typename_of<T>());
|
|
|
|
}
|
|
|
|
|
2012-10-27 16:04:13 +00:00
|
|
|
//
|
|
|
|
// print_type
|
|
|
|
//
|
|
|
|
template<typename T>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_type() {
|
2017-07-26 06:22:14 +00:00
|
|
|
testspr::print_ln(testspr::qualified_typename_of<T>());
|
2012-10-27 16:04:13 +00:00
|
|
|
}
|
|
|
|
|
2011-12-23 11:59:33 +00:00
|
|
|
//
|
|
|
|
// print_hl
|
|
|
|
//
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR void
|
|
|
|
print_hl() {
|
2012-02-25 02:51:23 +00:00
|
|
|
testspr::print_ln("--------------------------------------------------------------------------------");
|
2011-12-23 11:59:33 +00:00
|
|
|
}
|
2014-02-19 23:04:36 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// manip_holder
|
|
|
|
//
|
|
|
|
template<typename T>
|
|
|
|
class manip_holder {
|
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
private:
|
|
|
|
value_type m_;
|
|
|
|
public:
|
2014-07-22 00:33:13 +00:00
|
|
|
SPROUT_CONSTEXPR manip_holder(value_type const& m)
|
2014-02-19 23:04:36 +00:00
|
|
|
: m_(m)
|
|
|
|
{}
|
2014-07-22 00:33:13 +00:00
|
|
|
SPROUT_CONSTEXPR value_type const& get() const {
|
2014-02-19 23:04:36 +00:00
|
|
|
return m_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename T, typename Elem, typename Traits>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR std::basic_ostream<Elem, Traits>&
|
|
|
|
operator<<(std::basic_ostream<Elem, Traits>& lhs, testspr::manip_holder<T> const& rhs) {
|
2014-02-19 23:04:36 +00:00
|
|
|
return lhs << rhs.get();
|
|
|
|
}
|
|
|
|
template<typename T, typename Elem, typename Traits>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR std::basic_istream<Elem, Traits>&
|
|
|
|
operator>>(std::basic_istream<Elem, Traits>& lhs, testspr::manip_holder<T> const& rhs) {
|
2014-02-19 23:04:36 +00:00
|
|
|
return lhs >> rhs.get();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// manip
|
|
|
|
//
|
|
|
|
template<typename T>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR T&&
|
2014-02-19 23:04:36 +00:00
|
|
|
manip(T&& t) {
|
|
|
|
return std::forward<T>(t);
|
|
|
|
}
|
|
|
|
template<typename Elem, typename Traits>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR testspr::manip_holder<std::basic_ostream<Elem, Traits>& (*)(std::basic_ostream<Elem, Traits>&)>
|
2014-02-19 23:04:36 +00:00
|
|
|
manip(std::basic_ostream<Elem, Traits>& (*pf)(std::basic_ostream<Elem, Traits>&)) {
|
|
|
|
return pf;
|
|
|
|
}
|
|
|
|
template<typename Elem, typename Traits>
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR testspr::manip_holder<std::basic_ios<Elem, Traits>& (*)(std::basic_ios<Elem, Traits>&)>
|
2014-02-19 23:04:36 +00:00
|
|
|
manip(std::basic_ios<Elem, Traits>& (*pf)(std::basic_ios<Elem, Traits>&)) {
|
|
|
|
return pf;
|
|
|
|
}
|
2014-07-22 00:33:13 +00:00
|
|
|
inline SPROUT_NON_CONSTEXPR testspr::manip_holder<std::ios_base& (*)(std::ios_base&)>
|
2014-02-19 23:04:36 +00:00
|
|
|
manip(std::ios_base& (*pf)(std::ios_base&)) {
|
|
|
|
return pf;
|
|
|
|
}
|
2011-12-23 11:59:33 +00:00
|
|
|
} // namespace testspr
|
|
|
|
|
|
|
|
#endif // #ifndef TESTSPR_PRINT_HPP
|