Skip to content

Commit 92fdd0a

Browse files
committed
Make swap constexpr.
constexpr support for swap, relying on the fact that only built-in integers are handled. It allows to get rid of the <utility> include too.
1 parent 416ca98 commit 92fdd0a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: include/cpp-gray/gray.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <cstddef>
3131
#include <limits>
3232
#include <type_traits>
33-
#include <utility>
3433

3534
namespace cppgray
3635
{
@@ -253,7 +252,7 @@ namespace cppgray
253252
// Utility functions
254253

255254
template<typename Unsigned>
256-
auto swap(gray_code<Unsigned>& lhs, gray_code<Unsigned>& rhs) noexcept
255+
constexpr auto swap(gray_code<Unsigned>& lhs, gray_code<Unsigned>& rhs) noexcept
257256
-> void;
258257

259258
////////////////////////////////////////////////////////////

Diff for: include/cpp-gray/gray.inl

+4-3
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,12 @@ constexpr auto operator^=(Unsigned& lhs, gray_code<Unsigned> rhs) noexcept
416416
// Utility functions
417417

418418
template<typename Unsigned>
419-
auto swap(gray_code<Unsigned>& lhs, gray_code<Unsigned>& rhs) noexcept
419+
constexpr auto swap(gray_code<Unsigned>& lhs, gray_code<Unsigned>& rhs) noexcept
420420
-> void
421421
{
422-
using std::swap;
423-
swap(lhs.value, rhs.value);
422+
auto tmp = lhs.value;
423+
lhs.value = rhs.value;
424+
rhs.value = tmp;
424425
}
425426

426427
////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)