Skip to content

Commit

Permalink
Reformat code with clang-format-18
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 17, 2024
1 parent 893072c commit 9eca277
Show file tree
Hide file tree
Showing 83 changed files with 811 additions and 903 deletions.
53 changes: 32 additions & 21 deletions include/xrpl/basics/Expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,67 +136,76 @@ class [[nodiscard]] Expected

public:
template <typename U>
requires std::convertible_to<U, T> constexpr Expected(U && r)
: Base(T(std::forward<U>(r)))
requires std::convertible_to<U, T>
constexpr Expected(U&& r) : Base(T(std::forward<U>(r)))
{
}

template <typename U>
requires std::convertible_to<U, E> &&
(!std::is_reference_v<U>)constexpr Expected(Unexpected<U> e)
: Base(E(std::move(e.value())))
requires std::convertible_to<U, E> && (!std::is_reference_v<U>)
constexpr Expected(Unexpected<U> e) : Base(E(std::move(e.value())))
{
}

constexpr bool has_value() const
constexpr bool
has_value() const
{
return Base::has_value();
}

constexpr T const& value() const
constexpr T const&
value() const
{
return Base::value();
}

constexpr T& value()
constexpr T&
value()
{
return Base::value();
}

constexpr E const& error() const
constexpr E const&
error() const
{
return Base::error();
}

constexpr E& error()
constexpr E&
error()
{
return Base::error();
}

constexpr explicit operator bool() const
constexpr explicit
operator bool() const
{
return has_value();
}

// Add operator* and operator-> so the Expected API looks a bit more like
// what std::expected is likely to look like. See:
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0323r10.html
[[nodiscard]] constexpr T& operator*()
[[nodiscard]] constexpr T&
operator*()
{
return this->value();
}

[[nodiscard]] constexpr T const& operator*() const
[[nodiscard]] constexpr T const&
operator*() const
{
return this->value();
}

[[nodiscard]] constexpr T* operator->()
[[nodiscard]] constexpr T*
operator->()
{
return &this->value();
}

[[nodiscard]] constexpr T const* operator->() const
[[nodiscard]] constexpr T const*
operator->() const
{
return &this->value();
}
Expand All @@ -218,23 +227,25 @@ class [[nodiscard]] Expected<void, E>
}

template <typename U>
requires std::convertible_to<U, E> &&
(!std::is_reference_v<U>)constexpr Expected(Unexpected<U> e)
: Base(E(std::move(e.value())))
requires std::convertible_to<U, E> && (!std::is_reference_v<U>)
constexpr Expected(Unexpected<U> e) : Base(E(std::move(e.value())))
{
}

constexpr E const& error() const
constexpr E const&
error() const
{
return Base::error();
}

constexpr E& error()
constexpr E&
error()
{
return Base::error();
}

constexpr explicit operator bool() const
constexpr explicit
operator bool() const
{
return Base::has_value();
}
Expand Down
24 changes: 13 additions & 11 deletions include/xrpl/basics/FeeUnits.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class TaggedFee : private boost::totally_ordered<TaggedFee<UnitTag, T>>,
protected:
template <class Other>
static constexpr bool is_compatible_v =
std::is_arithmetic_v<Other>&& std::is_arithmetic_v<value_type>&&
std::is_convertible_v<Other, value_type>;
std::is_arithmetic_v<Other> && std::is_arithmetic_v<value_type> &&
std::is_convertible_v<Other, value_type>;

template <class OtherFee, class = enable_if_unit_t<OtherFee>>
static constexpr bool is_compatiblefee_v =
is_compatible_v<typename OtherFee::value_type>&&
std::is_same_v<UnitTag, typename OtherFee::unit_type>;
is_compatible_v<typename OtherFee::value_type> &&
std::is_same_v<UnitTag, typename OtherFee::unit_type>;

template <class Other>
using enable_if_compatible_t =
Expand All @@ -110,7 +110,8 @@ class TaggedFee : private boost::totally_ordered<TaggedFee<UnitTag, T>>,
{
}

constexpr TaggedFee& operator=(beast::Zero)
constexpr TaggedFee&
operator=(beast::Zero)
{
fee_ = 0;
return *this;
Expand Down Expand Up @@ -250,7 +251,8 @@ class TaggedFee : private boost::totally_ordered<TaggedFee<UnitTag, T>>,
}

/** Returns true if the amount is not zero */
explicit constexpr operator bool() const noexcept
explicit constexpr
operator bool() const noexcept
{
return fee_ != 0;
}
Expand Down Expand Up @@ -344,8 +346,8 @@ constexpr bool can_muldiv_source_v =

template <class Dest, class = enable_if_unit_t<Dest>>
constexpr bool can_muldiv_dest_v =
can_muldiv_source_v<Dest>&& // Dest is also a source
std::is_convertible_v<std::uint64_t, typename Dest::value_type> &&
can_muldiv_source_v<Dest> && // Dest is also a source
std::is_convertible_v<std::uint64_t, typename Dest::value_type> &&
sizeof(typename Dest::value_type) >= sizeof(std::uint64_t);

template <
Expand All @@ -354,8 +356,8 @@ template <
class = enable_if_unit_t<Source1>,
class = enable_if_unit_t<Source2>>
constexpr bool can_muldiv_sources_v =
can_muldiv_source_v<Source1>&& can_muldiv_source_v<Source2>&& std::
is_same_v<typename Source1::unit_type, typename Source2::unit_type>;
can_muldiv_source_v<Source1> && can_muldiv_source_v<Source2> &&
std::is_same_v<typename Source1::unit_type, typename Source2::unit_type>;

template <
class Source1,
Expand All @@ -365,7 +367,7 @@ template <
class = enable_if_unit_t<Source2>,
class = enable_if_unit_t<Dest>>
constexpr bool can_muldiv_v =
can_muldiv_sources_v<Source1, Source2>&& can_muldiv_dest_v<Dest>;
can_muldiv_sources_v<Source1, Source2> && can_muldiv_dest_v<Dest>;
// Source and Dest can be the same by default

template <
Expand Down
6 changes: 4 additions & 2 deletions include/xrpl/basics/IOUAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class IOUAmount : private boost::totally_ordered<IOUAmount>,
operator<(IOUAmount const& other) const;

/** Returns true if the amount is not zero */
explicit operator bool() const noexcept;
explicit
operator bool() const noexcept;

/** Return the sign of the amount */
int
Expand All @@ -109,7 +110,8 @@ inline IOUAmount::IOUAmount(std::int64_t mantissa, int exponent)
normalize();
}

inline IOUAmount& IOUAmount::operator=(beast::Zero)
inline IOUAmount&
IOUAmount::operator=(beast::Zero)
{
// The -100 is used to allow 0 to sort less than small positive values
// which will have a large negative exponent.
Expand Down
6 changes: 4 additions & 2 deletions include/xrpl/basics/Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ class Number
static constexpr Number
lowest() noexcept;

explicit operator XRPAmount() const; // round to nearest, even on tie
explicit operator rep() const; // round to nearest, even on tie
explicit
operator XRPAmount() const; // round to nearest, even on tie
explicit
operator rep() const; // round to nearest, even on tie

friend constexpr bool
operator==(Number const& x, Number const& y) noexcept
Expand Down
6 changes: 4 additions & 2 deletions include/xrpl/basics/XRPAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class XRPAmount : private boost::totally_ordered<XRPAmount>,
{
}

constexpr XRPAmount& operator=(beast::Zero)
constexpr XRPAmount&
operator=(beast::Zero)
{
drops_ = 0;
return *this;
Expand Down Expand Up @@ -155,7 +156,8 @@ class XRPAmount : private boost::totally_ordered<XRPAmount>,
}

/** Returns true if the amount is not zero */
explicit constexpr operator bool() const noexcept
explicit constexpr
operator bool() const noexcept
{
return drops_ != 0;
}
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/basics/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ class base_uint
return bytes;
}

base_uint<Bits, Tag>& operator=(beast::Zero)
base_uint<Bits, Tag>&
operator=(beast::Zero)
{
data_.fill(0);
return *this;
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/basics/safe_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace ripple {

template <class Dest, class Src>
static constexpr bool is_safetocasttovalue_v =
(std::is_integral_v<Src> && std::is_integral_v<Dest>)&&(
std::is_signed<Src>::value || std::is_unsigned<Dest>::value) &&
(std::is_integral_v<Src> && std::is_integral_v<Dest>) &&
(std::is_signed<Src>::value || std::is_unsigned<Dest>::value) &&
(std::is_signed<Src>::value != std::is_signed<Dest>::value
? sizeof(Dest) > sizeof(Src)
: sizeof(Dest) >= sizeof(Src));
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/basics/tagged_integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class tagged_integer
return *this;
}

explicit operator Int() const noexcept
explicit
operator Int() const noexcept
{
return m_value;
}
Expand Down
8 changes: 5 additions & 3 deletions include/xrpl/beast/container/detail/aged_ordered_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,9 @@ class aged_ordered_container
// set
template <bool maybe_multi = IsMulti, bool maybe_map = IsMap>
auto
insert(value_type&& value) -> typename std::
enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type;
insert(value_type&& value) -> typename std::enable_if<
!maybe_multi && !maybe_map,
std::pair<iterator, bool>>::type;

// multiset
template <bool maybe_multi = IsMulti, bool maybe_map = IsMap>
Expand Down Expand Up @@ -1795,7 +1796,8 @@ template <
template <bool maybe_multi, bool maybe_map>
auto
aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>::
insert(value_type&& value) -> typename std::
insert(value_type&& value) ->
typename std::
enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type
{
typename cont_type::insert_commit_data d;
Expand Down
10 changes: 6 additions & 4 deletions include/xrpl/beast/container/detail/aged_unordered_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,9 @@ class aged_unordered_container
// map, set
template <bool maybe_multi = IsMulti, bool maybe_map = IsMap>
auto
insert(value_type&& value) -> typename std::
enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type;
insert(value_type&& value) -> typename std::enable_if<
!maybe_multi && !maybe_map,
std::pair<iterator, bool>>::type;

// multimap, multiset
template <bool maybe_multi = IsMulti, bool maybe_map = IsMap>
Expand Down Expand Up @@ -2799,8 +2800,9 @@ aged_unordered_container<
Clock,
Hash,
KeyEqual,
Allocator>::insert(value_type&& value) -> typename std::
enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type
Allocator>::insert(value_type&& value) ->
typename std::
enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type
{
maybe_rehash(1);
typename cont_type::insert_commit_data d;
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/beast/hash/xxhasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class xxhasher
XXH3_64bits_update(state_, key, len);
}

explicit operator std::size_t() noexcept
explicit
operator std::size_t() noexcept
{
return XXH3_64bits_digest(state_);
}
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/beast/unit_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#ifndef BEAST_EXPECT
#define BEAST_EXPECT_S1(x) #x
#define BEAST_EXPECT_S2(x) BEAST_EXPECT_S1(x)
//#define BEAST_EXPECT(cond) {expect(cond, __FILE__ ":" ##
// #define BEAST_EXPECT(cond) {expect(cond, __FILE__ ":" ##
//__LINE__);}while(false){}
#define BEAST_EXPECT(cond) expect(cond, __FILE__ ":" BEAST_EXPECT_S2(__LINE__))
#endif
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/beast/utility/Journal.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ class Journal
return m_sink.active(m_level);
}

explicit operator bool() const
explicit
operator bool() const
{
return active();
}
Expand Down
6 changes: 4 additions & 2 deletions include/xrpl/json/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class StaticString
{
}

constexpr operator const char*() const
constexpr
operator const char*() const
{
return str_;
}
Expand Down Expand Up @@ -296,7 +297,8 @@ class Value

/** Returns false if this is an empty array, empty object, empty string,
or null. */
explicit operator bool() const;
explicit
operator bool() const;

/// Remove all object members and array elements.
/// \pre type() is arrayValue, objectValue, or nullValue
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/AccountID.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <xrpl/protocol/tokens.h>
// VFALCO Uncomment when the header issues are resolved
//#include <ripple/protocol/PublicKey.h>
// #include <ripple/protocol/PublicKey.h>
#include <xrpl/basics/UnorderedContainers.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/json/json_value.h>
Expand Down
Loading

0 comments on commit 9eca277

Please sign in to comment.