xref: /aosp_15_r20/external/armnn/third-party/mapbox/variant_io.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright (c) MapBox All rights reserved.
3 // SPDX-License-Identifier: BSD-3-Clause
4 //
5 
6 #ifndef MAPBOX_UTIL_VARIANT_IO_HPP
7 #define MAPBOX_UTIL_VARIANT_IO_HPP
8 
9 #include <iosfwd>
10 
11 #include <mapbox/variant.hpp>
12 
13 namespace mapbox {
14 namespace util {
15 
16 namespace detail {
17 // operator<< helper
18 template <typename Out>
19 class printer
20 {
21 public:
printer(Out & out)22     explicit printer(Out& out)
23         : out_(out) {}
24     printer& operator=(printer const&) = delete;
25 
26     // visitor
27     template <typename T>
operator ()(T const & operand) const28     void operator()(T const& operand) const
29     {
30         out_ << operand;
31     }
32 
33 private:
34     Out& out_;
35 };
36 }
37 
38 // operator<<
39 template <typename CharT, typename Traits, typename... Types>
40 VARIANT_INLINE std::basic_ostream<CharT, Traits>&
operator <<(std::basic_ostream<CharT,Traits> & out,variant<Types...> const & rhs)41 operator<<(std::basic_ostream<CharT, Traits>& out, variant<Types...> const& rhs)
42 {
43     detail::printer<std::basic_ostream<CharT, Traits>> visitor(out);
44     apply_visitor(visitor, rhs);
45     return out;
46 }
47 } // namespace util
48 } // namespace mapbox
49 
50 #endif // MAPBOX_UTIL_VARIANT_IO_HPP
51