xo-indentlog: cosmetic adj in cond.hpp

This commit is contained in:
Roland Conybeare 2026-01-20 16:45:40 -05:00
commit 048a190f51

View file

@ -20,51 +20,51 @@ namespace xo {
template <typename T, typename U> template <typename T, typename U>
struct cond_impl { struct cond_impl {
public: public:
cond_impl(bool condition, T const & then_value, U const & else_value) cond_impl(bool condition, const T & if_true, const U & if_false)
: condition_{condition}, : condition_{condition},
then_value_{then_value}, if_true_{if_true},
else_value_{else_value} {} if_false_{if_false} {}
bool condition() const { return condition_; } bool condition() const { return condition_; }
T const & then_value() const { return then_value_; } const T & if_true() const { return if_true_; }
U const & else_value() const { return else_value_; } const U & if_false() const { return if_false_; }
private: private:
bool condition_; bool condition_;
T then_value_; T if_true_;
U else_value_; U if_false_;
}; };
/** Create conditional stream inserter. /** Create conditional stream inserter.
* *
* @param condition when true, print @p then_value; otherwise print @p else_value * @param condition when true, print @p if_true; otherwise print @p if_false
* @param then_value value to print when condition is true * @param if_true value to print when condition is true
* @param else_value value to print when condition is false * @param if_false value to print when condition is false
* *
* Example: * Example:
* @code * @code
* std::cout << cond(ptr != nullptr, xtag("ptr", *ptr), "nullptr"); * std::cout << cond(ptr, xtag("ptr", *ptr), "nullptr");
* @endcode * @endcode
**/ **/
template <typename T, typename U> template <typename T, typename U>
auto auto
cond(bool condition, T && then_value, U && else_value) cond(bool condition, T && if_true, U && if_false)
{ {
return cond_impl<std::decay_t<T>, std::decay_t<U>> return cond_impl<std::decay_t<T>, std::decay_t<U>>
(condition, (condition,
std::forward<T>(then_value), std::forward<T>(if_true),
std::forward<U>(else_value)); std::forward<U>(if_false));
} }
/** Stream insertion operator for cond_impl **/ /** Stream insertion operator for cond_impl **/
template <typename T, typename U> template <typename T, typename U>
inline std::ostream & inline std::ostream &
operator<<(std::ostream & os, cond_impl<T, U> const & c) operator<<(std::ostream & os, const cond_impl<T, U> & c)
{ {
if (c.condition()) if (c.condition())
os << c.then_value(); os << c.if_true();
else else
os << c.else_value(); os << c.if_false();
return os; return os;
} }
@ -79,9 +79,9 @@ namespace xo {
const target_type & c) const target_type & c)
{ {
if (c.condition()) if (c.condition())
return ppdetail<T>::print_pretty(ppii, c.then_value()); return ppdetail<T>::print_pretty(ppii, c.if_true());
else else
return ppdetail<U>::print_pretty(ppii, c.else_value()); return ppdetail<U>::print_pretty(ppii, c.if_false());
} }
}; };
} }