Skip to content

Commit

Permalink
Merge pull request #579 from ckormanyos/more_syntax
Browse files Browse the repository at this point in the history
Handle more syntax improvements
  • Loading branch information
ckormanyos authored Nov 26, 2024
2 parents c67d228 + 88adec6 commit a57db52
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 65 deletions.
95 changes: 54 additions & 41 deletions ref_app/src/math/extended_complex/extended_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,25 @@
class complex
{
public:
typedef T value_type;
using value_type = T;

EXTENDED_COMPLEX_CONSTEXPR complex(const value_type& my_x = value_type(),
const value_type& my_y = value_type()) : my_re(my_x),
my_im(my_y) { }

EXTENDED_COMPLEX_CONSTEXPR complex(const complex& other) : my_re(other.real()),
my_im(other.imag()) { }
EXTENDED_COMPLEX_CONSTEXPR complex(const complex& other) : my_re(other.my_re),
my_im(other.my_im) { }

EXTENDED_COMPLEX_CONSTEXPR complex(complex&& other) noexcept : my_re(std::move(static_cast<value_type&&>(other.my_re))),
my_im(std::move(static_cast<value_type&&>(other.my_im))) { }
EXTENDED_COMPLEX_CONSTEXPR complex(complex&& other) noexcept
: my_re(std::move(static_cast<value_type&&>(other.my_re))),
my_im(std::move(static_cast<value_type&&>(other.my_im))) { }

template<typename X>
EXTENDED_COMPLEX_CONSTEXPR complex(const complex<X>& my_z) : my_re(static_cast<value_type>(my_z.real())),
my_im(static_cast<value_type>(my_z.imag())) { }
EXTENDED_COMPLEX_CONSTEXPR complex(const complex<X>& my_z)
: my_re(static_cast<value_type>(my_z.my_re)),
my_im(static_cast<value_type>(my_z.my_im)) { }

EXTENDED_COMPLEX_CONSTEXPR complex& operator=(const complex& other)
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex& other) -> complex&
{
if(this != &other)
{
Expand All @@ -183,7 +185,7 @@
return *this;
}

EXTENDED_COMPLEX_CONSTEXPR complex& operator=(complex&& other) noexcept
EXTENDED_COMPLEX_CONSTEXPR auto operator=(complex&& other) noexcept -> complex&
{
my_re = std::move(static_cast<value_type&&>(other.my_re));
my_im = std::move(static_cast<value_type&&>(other.my_im));
Expand All @@ -192,18 +194,26 @@
}

template<typename X>
EXTENDED_COMPLEX_CONSTEXPR complex& operator=(const complex<X>& other)
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const complex<X>& other) -> complex&
{
my_re = static_cast<value_type>(other.my_re);
my_im = static_cast<value_type>(other.my_im);

return *this;
}

EXTENDED_COMPLEX_CONSTEXPR complex& operator=(const value_type& other_x)
EXTENDED_COMPLEX_CONSTEXPR auto operator=(const value_type& other_x) -> complex&
{
my_re = other_x;
my_im = static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)));
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));

return *this;
}

EXTENDED_COMPLEX_CONSTEXPR auto operator=(value_type&& other_x) noexcept -> complex&
{
my_re = std::move(other_x);
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));

return *this;
}
Expand All @@ -214,6 +224,9 @@
EXTENDED_COMPLEX_CONSTEXPR auto real(const value_type& my_x) -> void { my_re = my_x; }
EXTENDED_COMPLEX_CONSTEXPR auto imag(const value_type& my_y) -> void { my_im = my_y; }

EXTENDED_COMPLEX_CONSTEXPR auto real(value_type&& my_x) noexcept -> void { my_re = std::move(my_x); }
EXTENDED_COMPLEX_CONSTEXPR auto imag(value_type&& my_y) noexcept -> void { my_im = std::move(my_y); }

EXTENDED_COMPLEX_CONSTEXPR auto operator+=(const value_type& my_x) -> complex&
{
my_re += my_x;
Expand Down Expand Up @@ -258,8 +271,8 @@
{
if(this == &my_z)
{
my_re = static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)));
my_im = static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)));
real(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
}
else
{
Expand All @@ -273,17 +286,17 @@
template<typename X>
EXTENDED_COMPLEX_CONSTEXPR auto operator*=(const complex<X>& my_z) -> complex&
{
const value_type tmp_re(my_re);
const value_type tmp_re { my_re };

if(this == &my_z)
{
my_re = (tmp_re * tmp_re) - (my_im * my_im);
my_im = (tmp_re * my_im) * 2U;
real((tmp_re * tmp_re) - (my_im * my_im));
imag((tmp_re * my_im) * 2U);
}
else
{
my_re = (tmp_re * my_z.my_re) - (my_im * my_z.my_im);
my_im = (tmp_re * my_z.my_im) + (my_im * my_z.my_re);
real((tmp_re * my_z.my_re) - (my_im * my_z.my_im));
imag((tmp_re * my_z.my_im) + (my_im * my_z.my_re));
}

return *this;
Expand All @@ -294,32 +307,32 @@
{
if(this == &my_z)
{
my_re = static_cast<value_type>(static_cast<unsigned>(UINT8_C(1)));
my_im = static_cast<value_type>(static_cast<unsigned>(UINT8_C(0)));
real(static_cast<value_type>(static_cast<unsigned>(UINT8_C(1))));
imag(static_cast<value_type>(static_cast<unsigned>(UINT8_C(0))));
}
else
{
if(fabs(my_z.real()) < fabs(my_z.imag()))
if(fabs(my_z.my_re) < fabs(my_z.my_im))
{
const value_type my_c_over_d = my_z.real() / my_z.imag();
const value_type my_c_over_d { my_z.my_re / my_z.my_im };

const value_type my_denominator = (my_z.real() * my_c_over_d) + my_z.imag();
const value_type my_denominator { (my_z.my_re * my_c_over_d) + my_z.my_im };

const value_type my_tmp_re(my_re);
const value_type my_tmp_re { my_re };

my_re = ((my_tmp_re * my_c_over_d) + my_im) / my_denominator;
my_im = ((my_im * my_c_over_d) - my_tmp_re) / my_denominator;
real(((my_tmp_re * my_c_over_d) + my_im) / my_denominator);
imag(((my_im * my_c_over_d) - my_tmp_re) / my_denominator);
}
else
{
const value_type my_d_over_c = my_z.imag() / my_z.real();
const value_type my_d_over_c { my_z.my_im / my_z.my_re };

const value_type my_denominator = (my_z.imag() * my_d_over_c) + my_z.real();
const value_type my_denominator { (my_z.my_im * my_d_over_c) + my_z.my_re };

const value_type my_tmp_re(my_re);
const value_type my_tmp_re { my_re };

my_re = (( my_im * my_d_over_c) + my_tmp_re) / my_denominator;
my_im = ((-my_tmp_re * my_d_over_c) + my_im) / my_denominator;
real((( my_im * my_d_over_c) + my_tmp_re) / my_denominator);
imag(((-my_tmp_re * my_d_over_c) + my_im) / my_denominator);
}
}

Expand Down Expand Up @@ -394,8 +407,8 @@
return *this;
}

EXTENDED_COMPLEX_CONSTEXPR value_type real() const { return my_re; }
EXTENDED_COMPLEX_CONSTEXPR value_type imag() const { return my_im; }
EXTENDED_COMPLEX_CONSTEXPR auto real() const -> value_type { return my_re; }
EXTENDED_COMPLEX_CONSTEXPR auto imag() const -> value_type { return my_im; }

EXTENDED_COMPLEX_CONSTEXPR auto real(const value_type& my_x) -> void { my_re = my_x; }
EXTENDED_COMPLEX_CONSTEXPR auto imag(const value_type& my_y) -> void { my_im = my_y; }
Expand Down Expand Up @@ -459,7 +472,7 @@
template<typename X>
EXTENDED_COMPLEX_CONSTEXPR auto operator*=(const complex<X>& my_z) -> complex&
{
const value_type tmp_re(my_re);
const value_type tmp_re { my_re };

if(this == &my_z)
{
Expand Down Expand Up @@ -489,22 +502,22 @@

if(fabs(my_z.real()) < fabs(my_z.imag()))
{
const value_type my_c_over_d = my_z.real() / my_z.imag();
const value_type my_c_over_d { my_z.real() / my_z.imag() };

const value_type my_denominator = (my_z.real() * my_c_over_d) + my_z.imag();
const value_type my_denominator { (my_z.real() * my_c_over_d) + my_z.imag() };

const value_type my_tmp_re(my_re);
const value_type my_tmp_re { my_re };

real(((my_tmp_re * my_c_over_d) + my_im) / my_denominator);
imag(((my_im * my_c_over_d) - my_tmp_re) / my_denominator);
}
else
{
const value_type my_d_over_c = my_z.imag() / my_z.real();
const value_type my_d_over_c { my_z.imag() / my_z.real() };

const value_type my_denominator = (my_z.imag() * my_d_over_c) + my_z.real();
const value_type my_denominator { (my_z.imag() * my_d_over_c) + my_z.real() };

const value_type my_tmp_re(my_re);
const value_type my_tmp_re { my_re };

real((( my_im * my_d_over_c) + my_tmp_re) / my_denominator);
imag(((-my_tmp_re * my_d_over_c) + my_im) / my_denominator);
Expand Down
48 changes: 24 additions & 24 deletions ref_app/src/util/STL/array
Original file line number Diff line number Diff line change
Expand Up @@ -41,72 +41,72 @@

static STL_LOCAL_CONSTEXPR size_type static_size = N;

STL_LOCAL_CONSTEXPR_ALGORITHMS iterator begin() { return elems; }
STL_LOCAL_CONSTEXPR_ALGORITHMS iterator end () { return elems + N; }
STL_LOCAL_CONSTEXPR iterator begin() { return elems; }
STL_LOCAL_CONSTEXPR iterator end () { return elems + N; }

STL_LOCAL_CONSTEXPR const_iterator begin() const { return elems; }
STL_LOCAL_CONSTEXPR const_iterator end () const { return elems + N; }

STL_LOCAL_CONSTEXPR const_iterator cbegin() const { return elems; }
STL_LOCAL_CONSTEXPR const_iterator cend () const { return elems + N; }

STL_LOCAL_CONSTEXPR_ALGORITHMS reverse_iterator rbegin() { return reverse_iterator(elems + N); }
STL_LOCAL_CONSTEXPR_ALGORITHMS reverse_iterator rend () { return reverse_iterator(elems); }
STL_LOCAL_CONSTEXPR reverse_iterator rbegin() { return reverse_iterator(elems + N); }
STL_LOCAL_CONSTEXPR reverse_iterator rend () { return reverse_iterator(elems); }

STL_LOCAL_CONSTEXPR const_reverse_iterator rbegin() const { return const_reverse_iterator(elems + N); }
STL_LOCAL_CONSTEXPR const_reverse_iterator rend () const { return const_reverse_iterator(elems); }

STL_LOCAL_CONSTEXPR const_reverse_iterator crbegin() const { return const_reverse_iterator(elems + N); }
STL_LOCAL_CONSTEXPR const_reverse_iterator crend () const { return const_reverse_iterator(elems); }

STL_LOCAL_CONSTEXPR_ALGORITHMS reference operator[](const size_type i) { return elems[i]; }
STL_LOCAL_CONSTEXPR const_reference operator[](const size_type i) const { return elems[i]; }
STL_LOCAL_CONSTEXPR reference operator[](const size_type i) { return elems[i]; }
STL_LOCAL_CONSTEXPR const_reference operator[](const size_type i) const { return elems[i]; }

STL_LOCAL_CONSTEXPR_ALGORITHMS reference at(const size_type i) { return elems[i]; }
STL_LOCAL_CONSTEXPR const_reference at(const size_type i) const { return elems[i]; }
STL_LOCAL_CONSTEXPR reference at(const size_type i) { return elems[i]; }
STL_LOCAL_CONSTEXPR const_reference at(const size_type i) const { return elems[i]; }

STL_LOCAL_CONSTEXPR_ALGORITHMS reference front() { return elems[0U]; }
STL_LOCAL_CONSTEXPR const_reference front() const { return elems[0U]; }
STL_LOCAL_CONSTEXPR reference front() { return elems[0U]; }
STL_LOCAL_CONSTEXPR const_reference front() const { return elems[0U]; }

STL_LOCAL_CONSTEXPR_ALGORITHMS reference back() { return elems[N - 1U]; }
STL_LOCAL_CONSTEXPR const_reference back() const { return elems[N - 1U]; }
STL_LOCAL_CONSTEXPR reference back() { return elems[N - 1U]; }
STL_LOCAL_CONSTEXPR const_reference back() const { return elems[N - 1U]; }

static STL_LOCAL_CONSTEXPR size_type size() { return N; }
static STL_LOCAL_CONSTEXPR bool empty() { return false; }
static STL_LOCAL_CONSTEXPR size_type max_size() { return N; }

template<typename T2>
STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(array<T2, N>& y)
STL_LOCAL_CONSTEXPR void swap(array<T2, N>& y)
{
std::swap_ranges(begin(), end(), y.begin());
}

STL_LOCAL_CONSTEXPR const_pointer data() const { return elems; }
STL_LOCAL_CONSTEXPR_ALGORITHMS pointer data() { return elems; }
STL_LOCAL_CONSTEXPR const_pointer data() const { return elems; }
STL_LOCAL_CONSTEXPR pointer data() { return elems; }

pointer c_array() { return elems; }

template<typename T2>
STL_LOCAL_CONSTEXPR_ALGORITHMS array& operator=(const array<T2, N>& y)
STL_LOCAL_CONSTEXPR array& operator=(const array<T2, N>& y)
{
std::copy(y.begin(), y.end(), begin());

return *this;
}

STL_LOCAL_CONSTEXPR_ALGORITHMS void assign(const value_type& value)
STL_LOCAL_CONSTEXPR void assign(const value_type& value)
{
std::fill_n(elems, N, value);
}

STL_LOCAL_CONSTEXPR_ALGORITHMS void fill(const value_type& value)
STL_LOCAL_CONSTEXPR void fill(const value_type& value)
{
std::fill_n(elems, N, value);
}
};

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator==(const array<T, N>& left, const array<T, N>& right)
STL_LOCAL_CONSTEXPR bool operator==(const array<T, N>& left, const array<T, N>& right)
{
return std::equal(left.begin(), left.end(), right.begin());
}
Expand All @@ -121,31 +121,31 @@
}

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator!=(const array<T, N>& left, const array<T, N>& right)
STL_LOCAL_CONSTEXPR bool operator!=(const array<T, N>& left, const array<T, N>& right)
{
return (!(left == right));
}

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator>(const array<T, N>& left, const array<T, N>& right)
STL_LOCAL_CONSTEXPR bool operator>(const array<T, N>& left, const array<T, N>& right)
{
return (right < left);
}

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator>=(const array<T, N>& left, const array<T, N>& right)
STL_LOCAL_CONSTEXPR bool operator>=(const array<T, N>& left, const array<T, N>& right)
{
return (!(left < right));
}

template<typename T, size_t N>
STL_LOCAL_CONSTEXPR_ALGORITHMS bool operator<=(const array<T, N>& left, const array<T, N>& right)
STL_LOCAL_CONSTEXPR bool operator<=(const array<T, N>& left, const array<T, N>& right)
{
return (!(right < left));
}

template<typename T, size_t N >
STL_LOCAL_CONSTEXPR_ALGORITHMS void swap(array<T, N>& x, array<T, N>& y)
STL_LOCAL_CONSTEXPR void swap(array<T, N>& x, array<T, N>& y)
{
swap_ranges(x.begin(), x.end(), y.begin());
}
Expand Down

0 comments on commit a57db52

Please sign in to comment.