12#ifndef _TPF_OUTPUT_HPP
13#define _TPF_OUTPUT_HPP
15#ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES
16 #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
24 #if _MSVC_LANG < 201703L
25 #error This libary requires C++17 Standard (Visual Studio 2017).
29 #if __cplusplus < 201703
30 #error This library requires C++17 Standard (GNU g++ version 8.0 or clang++ version 8.0 above)
43#if defined(TPF_USE_STD_EXTENSION_ARRAY_TUPLE)
59 template<
typename CharType,
typename T>
60 std::basic_ostream<CharType>&
operator<<
63 template<
typename CharType,
typename... ElementTypes>
64 std::basic_ostream<CharType>&
operator<<
65 (std::basic_ostream<CharType>& os,
const tpf::types::any<ElementTypes...>& a);
67 template<
typename CharType,
typename T>
68 std::basic_ostream<CharType>&
69 operator<<(std::basic_ostream<CharType>& os,
const std::optional<T>& opt);
71 template<
typename CharType, auto N, auto D>
72 std::basic_ostream<CharType>&
73 operator<<(std::basic_ostream<CharType>& os,
const std::ratio<N, D>& r)
78 os <<
"< "<< r.num <<
" >";
80 os <<
"< " << r.num <<
" / " << r.den <<
" > ";
85 template<
typename CharType>
86 std::basic_ostream<CharType>&
87 operator<<(std::basic_ostream<CharType>& os,
const std::byte& b)
89 os << tpf::bitwise::to_bits<char>(std::to_integer<char>(b));
94 template<
typename CharType, auto IndexValue>
95 std::basic_ostream<CharType>&
99 os <<
"< " << indexer.
Index <<
" >" ;
return os;
102 template<
typename CharType, auto RowValue, auto ColumnValue>
103 std::basic_ostream<CharType>&
107 os <<
"< " << indexer.
Row <<
", " << indexer.
Column<<
" >";
return os;
110 template<
typename CharType, auto HeightValue, auto RowValue, auto ColumnValue>
111 std::basic_ostream<CharType>&
115 os <<
"< " << indexer.
Height <<
", "<< indexer.
Row <<
", " << indexer.
Column<<
" >";
return os;
118 template<
typename CharType,
typename Type,
int Tag>
119 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
122 template<
typename CharType,
typename Type>
123 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
124 const std::initializer_list<Type>& init_list);
126 template<
typename CharType,
template<
auto...>
class ContainerType,
127 auto... Ints> std::basic_ostream<CharType>&
128 operator>>(std::basic_ostream<CharType>& os,
const ContainerType<Ints...>& seq);
130 template<
typename CharType,
typename T, auto FirstValue, auto LastValue,
size_t CountValue,
bool stack_order>
131 std::basic_ostream<CharType>&
136 << seq.
Last<<
", End: "<< seq.
End <<
", Span: " << seq.
Span
137 <<
", Count: " << seq.
Count<<
", InOrder: " << seq.
InOrder <<
" }";
142 template<
typename CharType,
143 typename T, T... Ints> std::basic_ostream<CharType>&
144 operator<<(std::basic_ostream<CharType>& os,
const std::integer_sequence<T, Ints...>& seq)
146 constexpr auto Size =
sizeof...(Ints);
154 std::array<T, Size> array{ Ints...};
160 for(
size_t i = 0; i < Size; ++i)
164 if(i + 1 != Size) os <<
", ";
173 template<
typename CharType,
template<
auto...>
class ContainerType,
174 auto... Ints> std::basic_ostream<CharType>&
175 operator>>(std::basic_ostream<CharType>& os,
const ContainerType<Ints...>& seq)
177 constexpr auto Size =
sizeof...(Ints);
179 std::array array{ Ints...};
191 for(
size_t i = 0; i < Size; ++i)
195 if(i + 1 != Size) os <<
", ";
205 template<
typename CharType,
206 typename T, T... Ints> std::basic_ostream<CharType>&
207 operator>>(std::basic_ostream<CharType>& os,
const std::integer_sequence<T, Ints...>& seq)
209 constexpr auto Size =
sizeof...(Ints);
211 std::array array{ Ints...};
223 for(
size_t i = 0; i < Size; ++i)
227 if(i + 1 != Size) os <<
", ";
236 template<
typename CharType> std::basic_ostream<CharType>&
250 os <<
"Unknown";
return os;
261 inline std::ostream&
operator<<(std::ostream& os,
const std::wstring& str)
263 os << conversion::source_to_target<char, wchar_t>(str);
274 inline std::ostream&
operator<<(std::ostream& os,
const wchar_t* str)
276 os << conversion::source_to_target<char, wchar_t>(str);
287 inline std::wostream&
operator<<(std::wostream& os,
const std::string& str)
289 os << conversion::source_to_target<wchar_t, char>(str);
300 template<
typename CharType,
template<
typename,
typename...>
class ContainerType,
301 typename Type,
typename... Types>
305 std::basic_ostream<CharType>&>;
309 template<
typename CharType,
typename FirstType,
typename SecondType>
310 std::basic_ostream<CharType>&
311 operator<<(std::basic_ostream<CharType>& os,
const std::pair<FirstType, SecondType>& pr);
313 template<
typename CharType,
typename... Types>
314 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
315 const std::tuple<Types...>& tuple);
317 template<
typename CharType,
typename Type,
typename... Types>
318 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
319 const std::variant<Type, Types...>& variant);
321 template<
typename CharType,
typename Type_1,
typename Type_2>
322 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
323 const std::unique_ptr<Type_1, Type_2>& ptr);
325 template<
typename CharType,
typename Type>
326 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
327 const std::shared_ptr<Type>& ptr);
329 template<
typename CharType,
typename ElementType,
size_t Size>
330 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
331 const std::array<ElementType, Size>& array);
333 #ifdef _TPF_CUDA_EXTENSIONS_HPP
334 template<
typename CharType,
typename... Types>
335 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
336 thrust::tuple<Types...>
const& tuple);
350 template<
typename CharType,
template<
typename,
typename...>
class ContainerType,
351 typename Type,
typename... Types>
353 operator<<(std::basic_ostream<CharType>& os,
const ContainerType<Type, Types...>& container)
357 if(container.empty())
364 auto last_element = container.cend();
368 for(
auto itr = container.cbegin(); itr != container.cend(); )
374 if(itr == container.cend())
384 template<
typename CharType,
typename ElementType,
size_t Size>
385 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
const std::array<ElementType, Size>& array)
389 os <<
"< >";
return os;
393 auto last = array.end();
397 for(
auto itr = array.begin(); itr != last; ++itr)
407 template<
typename CharType,
typename Type,
int Tag>
408 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
411 os << ncw.
get();
return os;
424 template<
typename CharType,
typename FirstType,
typename SecondType>
425 std::basic_ostream<CharType>&
426 operator<<(std::basic_ostream<CharType>& os,
const std::pair<FirstType, SecondType>& pr)
428 os <<
"{ " << pr.first <<
", " << pr.second <<
" }";
432 template<
typename CharType,
typename FirstType,
typename SecondType>
433 std::basic_ostream<CharType>&
437 auto [ptr,
size] = array;
439 if(types::is_string_v<FirstType> &&
446 for(
size_t i = 0; i < (size_t)size-1; ++i)
447 os << *(ptr+i) <<
", ";
449 os << *(ptr+
size-1) <<
" }";
455 template<
typename CharType,
typename... Types>
456 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
462 template<
typename CharType>
463 static void print_type_list(std::basic_ostream<CharType>& os) { }
465 template<
typename CharType,
typename Type,
typename... Types>
466 static void print_type_list(std::basic_ostream<CharType>& os)
468 if constexpr (types::is_type_list_v<Type>)
476 if constexpr(
sizeof...(Types) != 0)
479 print_type_list<CharType, Types...>(os);
483 template<
typename CharType,
typename... Types>
484 void print_type_list(std::basic_ostream<CharType>& os,
487 if constexpr(
sizeof...(Types)==0)
492 print_type_list<CharType, Types...>(os);
499 template<
typename CharType,
typename... Types>
500 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
503 hidden::print_type_list(os, typelist);
507 template<
typename CharType>
508 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
509 const std::exception& expt)
515 template<
typename CharType,
typename... Types>
516 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
517 const std::tuple<Types...>& tuple)
519 constexpr int Size =
sizeof...(Types);
521 if constexpr(Size == 0)
523 os <<
"[ ]";
return os;
529 types::for_workhorse<Size>([&os, &tuple](
auto i,
auto info)
533 if(i.Index != info.Last)
543 template<
typename CharType,
typename Type,
typename... Types>
544 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
545 const std::variant<Type, Types...>& variant)
548 if(std::variant_npos == variant.index())
552 constexpr int Size =
sizeof...(Types) + 1;
554 types::for_workhorse<Size>([&os, &variant](
auto i)
556 if(i.Index == variant.index())
558 if constexpr( std::is_same_v<std::monostate,
559 std::variant_alternative_t<i.Index, std::variant<Type, Types...>>>)
565 os << std::get<i.Index>(variant);
574 template<
typename CharType,
typename Type_1,
typename Type_2>
575 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
576 const std::unique_ptr<Type_1, Type_2>& ptr)
582 template<
typename CharType,
typename Type>
583 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
584 const std::shared_ptr<Type>& ptr)
590 template<
typename CharType,
template<
typename,
typename...>
class ContainerType,
591 typename... ElementTypes>
592 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
593 const types::hidden::container_of_variants_class<ContainerType, ElementTypes...>& container)
597 if(container.empty())
604 auto last_element = container.cend();
608 for(
auto itr = container.cbegin(); itr != container.cend(); )
614 if(itr == container.cend())
624 template<
typename CharType,
template<
typename,
typename...>
class ContainerType,
625 typename... ElementTypes>
626 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
627 const types::hidden::container_of_tuples_class<ContainerType, ElementTypes...>& container)
631 if(container.empty())
638 auto last_element = container.cend();
642 for(
auto itr = container.cbegin(); itr != container.cend(); )
648 if(itr == container.cend())
658 template<
typename CharType,
typename ContainerType>
659 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
664 if(container.
empty())
671 auto last_element = container.
cend();
675 for(
auto itr = container.
cbegin(); itr != container.
cend(); )
681 if(itr == container.
cend())
691 template<
typename CharType,
size_t ElementCount>
692 std::basic_ostream<CharType>&
693 operator<<(std::basic_ostream<CharType>& os,
const std::byte(&array)[ElementCount])
697 if(ElementCount == 0)
704 auto last_idx = ElementCount-1;
706 for(
int idx = last_idx; idx > 0; --idx )
708 os << array[idx] <<
'\'';
717 template<
typename CharType,
typename T>
718 std::basic_ostream<CharType>&
operator<<
721 if constexpr(std::is_same_v<T, unsigned char> || std::is_same_v<T, char> )
729 template<
typename CharType,
typename ElementType,
size_t ElementCount>
730 std::enable_if_t<!types::is_char_v<ElementType>, std::basic_ostream<CharType>&>
731 operator<<(std::basic_ostream<CharType>& os,
const ElementType(&array)[ElementCount])
735 if(ElementCount == 0)
744 auto last_idx = ElementCount-1;
746 for(
size_t idx = 0; idx < last_idx; ++idx )
748 os << array[idx] <<
", ";
751 os << array[last_idx] <<
" >";
759 template<
typename CharType,
typename ElementType,
size_t ElementCount>
760 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
765 if(container.
empty())
772 auto last_element = container.
cend();
776 for(
auto itr = container.
cbegin(); itr != container.
cend(); )
782 if(itr == container.
cend())
792 template<
typename CharType,
typename Type>
793 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
794 const std::initializer_list<Type>& init_list)
796 std::vector<Type> vctr{init_list.begin(), init_list.end()};
797 os << vctr;
return os;
800 #ifdef _TPF_CUDA_EXTENSIONS_HPP
801 template<
typename CharType,
typename... Types>
802 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
803 thrust::tuple<Types...>
const& tuple)
806 thrust::tuple_size<thrust::tuple<Types...>>::value;
810 types::for_workhorse<N>([&tuple, &os](
auto i)
813 thrust::tuple_size<thrust::tuple<Types...>>::value;
817 if constexpr( i.Index != N - 1) os <<
", ";
820 os <<
" ]";
return os;
823 template<
typename CharType,
typename Type1,
typename Type2>
824 std::basic_ostream<CharType>&
operator<<(std::basic_ostream<CharType>& os,
825 thrust::pair<Type1, Type2>
const& pair)
827 os <<
"( "<<pair.first<<
", " << pair.second<<
" )";
return os;
852 return static_cast<base_t&
>(*this);
857 return static_cast<const base_t&
>(*this);
862 std() << std::boolalpha;
889 #ifndef _TPF_CUDA_EXTENSIONS_HPP
890 template<
typename ArgCharType>
898 template<std::
size_t N,
typename T,
typename deleter>
901 std() << upw.
ref();
return *
this;
918 std().clear();
std().str(
"");
925 std().clear();
std().str(
"");
933 std().clear();
std().str(
"");
942 std().clear();
std().str(
"");
946 operator std::string()
const
948 return this->
std().str();
953 return this->
std().str();
956 operator std::wstring()
const
961 operator const char*()
const
963 return this->
std().str().c_str();
980 template<
typename T,
typename = std::enable_if_t<!(types::is_tag_type_v<T> || types::is_numbers_type_v<T>)>>
988 template<
template<
typename...>
class TemplateType,
typename... Types>
993 os <<element_list_t{} ;
998 template<
typename Type,
int Tag>
1002 <<
", " << Tag <<
" >";
return os;
1005 template<
template<
auto...>
class ContainerType,
auto... Ints>
1008 os.
std() >> arg ;
return os;
1011 template<
template<
typename T, T...>
class TemplateType,
typename Type, Type... Args,
1015 os.
std() >> std::integer_sequence<
Type, Args...>{};
1019 template<
typename Type>
1022 os << arg <<
", ";
return os;
1025 template<
typename Type>
1028 os << arg ;
return os;
1031 template<
typename CharType,
typename T>
1032 std::basic_ostream<CharType>&
1033 operator<<(std::basic_ostream<CharType>& os,
const std::optional<T>& opt)
1043 template<
typename CharType,
typename... ElementTypes>
1044 std::basic_ostream<CharType>&
operator<<
1045 (std::basic_ostream<CharType>& os,
const tpf::types::any<ElementTypes...>& a)
1047 if(!a.std().has_value())
1049 os <<
"no_value";
return os;
1053 constexpr int Size =
sizeof...(ElementTypes);
1057 types::for_workhorse<Size>([&os, &a](
auto i)
1059 using element_types_t =
typename any<ElementTypes...>::element_types_t;
1063 if(
auto ptr = std::any_cast<element_t>(&a.std()))
1068 throw types::no_type_t{};
1078 template<
typename Type,
size_t CacheSize>
1082 os.
std() << cw.
get();
return os;
typename enable_if< predicate, ReturnType >::type enable_if_t
string_stream & operator=(const string_stream &)=default
string_stream(const string_stream &)=default
std::ostringstream base_t
const base_t & std() const
decltype(auto) cbegin() const noexcept
auto empty() const noexcept
decltype(auto) cend() const noexcept
const Type & get() const noexcept
std::string smart_encode(const char *arg)
constexpr decltype(auto) get(T(&c_array)[N]) noexcept
String conversions are implemented.
std::string smart_encode(const char *arg)
std::wstring utf8_to_utf16(const std::string &utf8str)
Converts UTF8 std::string to UTF16 std::wstring.
std::enable_if_t< types::is_empty_available_v< ContainerType< Type, Types... > > &&!types::is_basic_string_v< ContainerType< Type, Types... > >, std::basic_ostream< CharType > & > enable_stream_if_not_string_t
Stream output operators are defined.
string_stream & operator>(string_stream &os, Type &&arg)
constexpr new_line_flush endl()
sstream & operator>>(sstream &os, const TemplateType< Type, Args... > &)
string_stream & operator<(string_stream &os, Type &&arg)
std::basic_ostream< CharType > & operator>>(std::basic_ostream< CharType > &os, const ContainerType< Ints... > &seq)
constexpr flush_stream flush()
std::basic_ostream< CharType > & operator<<(std::basic_ostream< CharType > &os, const tpf::bitwise::bit_pattern< T > &a)
constexpr new_Line_flush endL()
sstream & operator<<(sstream &os, const tpf::parallel::cache_wrapper< Type, CacheSize > &cw)
constexpr bool is_tag_type_v
Type to string name conversions are defined.
constexpr bool is_empty_available_v
constexpr auto is_basic_string_v
hidden::to_recursive_type_list_t< remove_cv_ref_t< T > > to_recursive_type_list_t
hidden::select_nth_type_t< SelectIndex, Types... > select_nth_type_t
Includes subnamespace conversion.
remove_cv_ref_t< std::remove_pointer_t< decay_remove_cv_ref_t< Type > > > primitive_type_t
Decay, remove const, volatile, reference, then remove pointer and remove const and volatile.
const Type & get() const noexcept
static constexpr bool InOrder
static constexpr size_t Count
static constexpr T Column
static constexpr T Column
static constexpr T Height
This type is used to test validity of a type.
This type is used to manipulate type list.
Stream output operators << are implemented.
String conversions are implemented.
Type functions are implemented.
#define Tpf_GetTypeName(type_arg)
A macro that returns type_arg's string name.