Skip to content

Commit

Permalink
refs #3 Оператор явного преобразования к целым числам
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Nov 5, 2023
1 parent 13bef1d commit 002057b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/fftpp/ring/basic_ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ namespace fftpp

constexpr auto operator <=> (const basic_ring & that) const = default;

template <std::integral N>
constexpr explicit operator N () const
{
return static_cast<N>(m_value);
}

private:
friend std::ostream & operator << (std::ostream & stream, basic_ring x)
{
Expand Down
8 changes: 8 additions & 0 deletions test/fftpp/ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ TEST_CASE_TEMPLATE("Реализует операторы префиксного
}
}

TEST_CASE_TEMPLATE("Умеет преобразовываться к стандатным целочисленным типам",
ring,
fftpp::ring8, fftpp::ring16, fftpp::ring30)
{
auto x = static_cast<int>(ring{4});
CHECK(x == 4);
}

TEST_CASE_TEMPLATE("Реализует все операции сравнения со стандартной семантикой",
ring,
fftpp::ring8, fftpp::ring16, fftpp::ring30)
Expand Down

0 comments on commit 002057b

Please sign in to comment.