]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* Boost examples/io.cpp |
2 | * show some exampleso of i/o operators | |
3 | * thanks to all the people who commented on this point, particularly on | |
4 | * the Boost mailing-list | |
5 | * | |
6 | * Copyright 2003 Guillaume Melquiond | |
7 | * | |
8 | * Distributed under the Boost Software License, Version 1.0. | |
9 | * (See accompanying file LICENSE_1_0.txt or | |
10 | * copy at http://www.boost.org/LICENSE_1_0.txt) | |
11 | */ | |
12 | ||
13 | #include <boost/numeric/interval.hpp> | |
14 | #include <boost/io/ios_state.hpp> | |
15 | #include <cmath> | |
16 | #include <cassert> | |
17 | ||
18 | namespace io_std { | |
19 | ||
20 | template<class T, class Policies, class CharType, class CharTraits> | |
21 | std::basic_ostream<CharType, CharTraits> &operator<< | |
22 | (std::basic_ostream<CharType, CharTraits> &stream, | |
23 | const boost::numeric::interval<T, Policies> &value) | |
24 | { | |
25 | if (empty(value)) { | |
26 | return stream << "[]"; | |
27 | } else { | |
28 | return stream << '[' << lower(value) << ',' << upper(value) << ']'; | |
29 | } | |
30 | } | |
31 | ||
32 | } // namespace io_std | |
33 | ||
34 | namespace io_sngl { | |
35 | ||
36 | template<class T, class Policies, class CharType, class CharTraits> | |
37 | std::basic_ostream<CharType, CharTraits> &operator<< | |
38 | (std::basic_ostream<CharType, CharTraits> &stream, | |
39 | const boost::numeric::interval<T, Policies> &value) | |
40 | { | |
41 | if (empty(value)) { | |
42 | return stream << "[]"; | |
43 | } else if (singleton(value)) { | |
44 | return stream << '[' << lower(value) << ']'; | |
45 | } else { | |
46 | return stream << '[' << lower(value) << ',' << upper(value) << ']'; | |
47 | } | |
48 | } | |
49 | ||
50 | } // namespace io_sngl | |
51 | ||
52 | namespace io_wdth { | |
53 | ||
54 | template<class T, class Policies, class CharType, class CharTraits> | |
55 | std::basic_ostream<CharType, CharTraits> &operator<< | |
56 | (std::basic_ostream<CharType, CharTraits> &stream, | |
57 | const boost::numeric::interval<T, Policies> &value) | |
58 | { | |
59 | if (empty(value)) { | |
60 | return stream << "nothing"; | |
61 | } else { | |
62 |