24 template<
typename Array>
25 std::pair<std::intmax_t,std::size_t>
get_proper_suffix(std::intmax_t value,
const Array& a) {
27 std::intmax_t mult = 1;
28 for (;
id < a.size()-1; ++id) {
29 if (value < (a[
id].second * mult)) {
34 return std::make_pair(value / mult,
id);
45 template<
typename... Args>
47 constexpr
duration(Args&&... args): std::chrono::nanoseconds(std::forward<Args>(args)...) {}
48 template<
typename R,
typename P>
49 explicit constexpr
operator std::chrono::duration<R,P>()
const {
50 return std::chrono::duration_cast<std::chrono::duration<R,P>>(std::chrono::nanoseconds(*
this));
56 std::array<std::pair<std::string,intmax_t>,6> suffixes = {{
57 {
"ns", 1000}, {
"µs", 1000}, {
"ms", 1000},
58 {
"s", 60}, {
"m", 60}, {
"h", 1},
61 return os << res.first << suffixes[res.second].first;
83 constexpr
auto n()
const {
return mN; }
84 constexpr
auto kibi()
const {
return mN >> 10U; }
85 constexpr
auto mebi()
const {
return mN >> 20U; }
86 constexpr
auto gibi()
const {
return mN >> 30U; }
87 constexpr
auto tebi()
const {
return mN >> 40U; }
88 constexpr
auto pebi()
const {
return mN >> 50U; }
89 constexpr
auto exbi()
const {
return mN >> 60U; }
93 return lhs.
n() == rhs.
n();
97 return lhs.
n() < rhs.
n();
102 std::array<std::pair<std::string,long>,7> suffixes = {{
103 {
"", 1024}, {
"Ki", 1024}, {
"Mi", 1024},
104 {
"Gi", 1024}, {
"Ti", 1024}, {
"Pi", 1024}, {
"Ei", 1},
107 return os << res.first << suffixes[res.second].first;
129 constexpr
auto n()
const {
return mN; }
130 constexpr
auto kilo()
const {
return mN / 1000; }
131 constexpr
auto mega()
const {
return mN / 1000000; }
132 constexpr
auto giga()
const {
return mN / 1000000000; }
133 constexpr
auto tera()
const {
return mN / 1000000000000; }
134 constexpr
auto peta()
const {
return mN / 1000000000000000; }
135 constexpr
auto exa()
const {
return mN / 1000000000000000000; }
139 return lhs.
n() == rhs.
n();
143 return lhs.
n() < rhs.
n();
148 std::array<std::pair<std::string,long>,7> suffixes = {{
149 {
"", 1000}, {
"K", 1000}, {
"M", 1000},
150 {
"G", 1000}, {
"T", 1000}, {
"P", 1000}, {
"E", 1},
153 return os << res.first << suffixes[res.second].first;
std::pair< std::intmax_t, std::size_t > get_proper_suffix(std::intmax_t value, const Array &a)
Helper method to obtain proper (unit) suffix entry from a value and a given set of possible suffixes.
constexpr bool operator<(binary_quantity lhs, binary_quantity rhs)
Compare two binary quantities.
void validate(boost::any &v, const std::vector< std::string > &values, carl::settings::duration *, int)
Custom validator for duration that wraps some std::chrono::duration.
constexpr bool operator==(binary_quantity lhs, binary_quantity rhs)
Compare two binary quantities for equality.
std::ostream & operator<<(std::ostream &os, const duration &d)
Streaming operator for duration. Auto-detects proper time suffix.
Helper type to parse duration as std::chrono values with boost::program_options.
constexpr duration(Args &&... args)
Helper type to parse quantities with binary SI-style suffixes.
constexpr auto gibi() const
constexpr auto exbi() const
constexpr auto pebi() const
constexpr auto kibi() const
constexpr auto mebi() const
constexpr auto tebi() const
constexpr binary_quantity(std::size_t n)
constexpr binary_quantity()=default
Helper type to parse quantities with SI-style suffixes.
constexpr auto tera() const
constexpr auto kilo() const
constexpr metric_quantity(std::size_t n)
constexpr auto giga() const
constexpr auto peta() const
constexpr auto mega() const
constexpr metric_quantity()=default
constexpr auto exa() const