Skip to content

Commit

Permalink
Start process of syntax modernization
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Aug 5, 2024
1 parent c70368d commit c8c4e7f
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 94 deletions.
46 changes: 23 additions & 23 deletions ref_app/src/math/functions/math_functions_hypergeometric.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2014 - 2018.
// Copyright Christopher Kormanyos 2014 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H_
#define MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H_
#ifndef MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H
#define MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H

#include <util/memory/util_ring_allocator.h>
#include <util/utility/util_dynamic_array.h>

#include <algorithm>
#include <array>
Expand All @@ -17,17 +20,14 @@
#include <numeric>
#include <vector>

#include <util/memory/util_ring_allocator.h>
#include <util/utility/util_dynamic_array.h>

namespace math
{
namespace functions
{
template<typename T>
T hypergeometric_0f1(T b,
auto hypergeometric_0f1(T b,
T x,
T tolerance = std::numeric_limits<T>::epsilon() * T(10))
T tolerance = std::numeric_limits<T>::epsilon() * T(10)) -> T
{
// Compute the Taylor series representation of hypergeometric_0f1.
// There are no checks on input range or parameter boundaries.
Expand Down Expand Up @@ -70,22 +70,22 @@
}

template<typename T>
T hypergeometric_2f1(T a,
auto hypergeometric_2f1(T a,
T b,
T c,
T x,
T tolerance = std::numeric_limits<T>::epsilon() * T(10))
T tolerance = std::numeric_limits<T>::epsilon() * T(10)) -> T
{
// Compute the Taylor series representation of hypergeometric_2f1.
// There are no checks on input range or parameter boundaries.

T x_pow_n_div_n_fact (x);
T pochhammer_sequence_a(a);
T pochhammer_sequence_b(b);
T pochhammer_sequence_c(c);
T ap (a);
T bp (b);
T cp (c);
T x_pow_n_div_n_fact { x };
T pochhammer_sequence_a { a };
T pochhammer_sequence_b { b };
T pochhammer_sequence_c { c };
T ap { a };
T bp { b };
T cp { c };

T hypergeometric_2f1_result = T(1) + (((pochhammer_sequence_a * pochhammer_sequence_b) / pochhammer_sequence_c) * x_pow_n_div_n_fact);

Expand Down Expand Up @@ -125,12 +125,12 @@
template<typename T,
typename iterator_a_type,
typename iterator_b_type>
T hypergeometric_pfq(iterator_a_type coefficients_a_begin,
auto hypergeometric_pfq(iterator_a_type coefficients_a_begin,
iterator_a_type coefficients_a_end,
iterator_b_type coefficients_b_begin,
iterator_b_type coefficients_b_end,
T x,
T tolerance = std::numeric_limits<T>::epsilon() * T(10))
T tolerance = std::numeric_limits<T>::epsilon() * T(10)) -> T
{
const std::ptrdiff_t count_of_a_terms = std::distance(coefficients_a_begin, coefficients_a_end);
const std::ptrdiff_t count_of_b_terms = std::distance(coefficients_b_begin, coefficients_b_end);
Expand Down Expand Up @@ -161,10 +161,10 @@
T x_pow_n_div_n_fact(x);

// Define an allocator type for use in the containers below.
typedef util::ring_allocator<T> allocator_type;
using allocator_type = util::ring_allocator<T>;

// Define a container type for the upcoming calculation.
typedef util::dynamic_array<T, allocator_type> container_type;
using container_type = util::dynamic_array<T, allocator_type>;

// The pochhammer symbols for the multiplications in the series expansion
// will be stored in non-constant STL vectors.
Expand Down Expand Up @@ -192,7 +192,7 @@

T hypergeometric_pfq_result = my_one + first_term;

std::uint_fast16_t n;
std::uint_fast16_t n { };

// Calculate the maximum number of iterations allowed.
const std::uint_fast16_t max_iteration = static_cast<std::uint_fast16_t>(std::numeric_limits<T>::digits10 * 10);
Expand Down Expand Up @@ -247,4 +247,4 @@
}
} // namespace math::functions

#endif // MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H_
#endif // MATH_FUNCTIONS_HYPERGEOMETRIC_2014_04_29_H
3 changes: 3 additions & 0 deletions ref_app/src/util/STL/impl/alloc_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

#include <impl/ptr_traits.h>

#include <utility>


namespace std
{
template<typename T>
Expand Down
2 changes: 2 additions & 0 deletions ref_app/src/util/STL/impl/ptr_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#ifndef PTR_TRAITS_2021_01_26_H_
#define PTR_TRAITS_2021_01_26_H_

#include <type_traits>

namespace std
{
template<typename...>
Expand Down
8 changes: 4 additions & 4 deletions ref_app/src/util/memory/util_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

/*
// See also link at GodBolt: https://godbolt.org/z/7fjcGTbWj
// See also link at GodBolt: https://godbolt.org/z/WrTTa8Eq9
#include <util/memory/util_factory.h>
Expand All @@ -74,8 +74,8 @@
class something : public util::factory_product
{
public:
something() { }
virtual ~something() { }
something() = default;
virtual ~something() = default;
private:
virtual void init() { }
Expand All @@ -88,7 +88,7 @@ class another : public util::factory_product
: my_m(m),
my_n(n) { }
~another() override { }
~another() override = default;
auto get_m() const -> int { return my_m; }
auto get_n() const -> int { return my_n; }
Expand Down
58 changes: 29 additions & 29 deletions ref_app/src/util/memory/util_ring_allocator.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2021.
// Copyright Christopher Kormanyos 2007 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef UTIL_RING_ALLOCATOR_2010_02_23_H_
#define UTIL_RING_ALLOCATOR_2010_02_23_H_
#ifndef UTIL_RING_ALLOCATOR_2010_02_23_H
#define UTIL_RING_ALLOCATOR_2010_02_23_H

#include <util/utility/util_alignas.h>

#include <cstddef>
#include <cstdint>
#include <memory>

#include <util/utility/util_alignas.h>

namespace util
{
class ring_allocator_base
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

virtual ~ring_allocator_base() = default;

Expand All @@ -41,7 +41,7 @@

// The ring allocator's memory allocation.
template<const std::uint_fast8_t buffer_alignment>
static void* do_allocate(size_type chunk_size)
static auto do_allocate(size_type chunk_size) -> void*
{
ALIGNAS(16) static buffer_type buffer;

Expand Down Expand Up @@ -80,14 +80,14 @@
};

// Global comparison operators (required by the standard).
inline bool operator==(const ring_allocator_base&,
const ring_allocator_base&) noexcept
inline auto operator==(const ring_allocator_base&,
const ring_allocator_base&) noexcept -> bool
{
return true;
}

inline bool operator!=(const ring_allocator_base&,
const ring_allocator_base&) noexcept
inline auto operator!=(const ring_allocator_base&,
const ring_allocator_base&) noexcept -> bool
{
return false;
}
Expand All @@ -100,9 +100,9 @@
class ring_allocator<void, buffer_alignment> : public ring_allocator_base
{
public:
typedef void value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
using value_type = void;
using pointer = value_type*;
using const_pointer = const value_type*;

template<typename U>
struct rebind
Expand All @@ -119,11 +119,11 @@
static_assert(sizeof(T) <= buffer_type::size,
"The size of the allocation object can not exceed the buffer size.");

typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
using value_type = T;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;

ring_allocator() noexcept = default;

Expand All @@ -138,16 +138,16 @@
using other = ring_allocator<U, buffer_alignment>;
};

size_type max_size() const noexcept
auto max_size() const noexcept -> size_type
{
return buffer_type::size / sizeof(value_type);
}

pointer address( reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
auto address( reference x) const -> pointer { return &x; }
auto address(const_reference x) const -> const_pointer { return &x; }

pointer allocate(size_type count,
typename ring_allocator<void, buffer_alignment>::const_pointer = nullptr)
auto allocate(size_type count,
typename ring_allocator<void, buffer_alignment>::const_pointer = nullptr) -> pointer
{
const size_type chunk_size = count * sizeof(value_type);

Expand All @@ -156,15 +156,15 @@
return static_cast<pointer>(p);
}

void construct(pointer p, const value_type& x) noexcept
auto construct(pointer p, const value_type& x) noexcept -> void
{
new(static_cast<void*>(p)) value_type(x);
}

void destroy(pointer p) noexcept { p->~value_type(); }
auto destroy(pointer p) noexcept -> void { p->~value_type(); }

void deallocate(pointer, size_type) noexcept { }
auto deallocate(pointer, size_type) noexcept -> void { }
};
}

#endif // UTIL_RING_ALLOCATOR_2010_02_23_H_
#endif // UTIL_RING_ALLOCATOR_2010_02_23_H
44 changes: 32 additions & 12 deletions ref_app/src/util/utility/util_bit_mask.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2018.
// Copyright Christopher Kormanyos 2007 - 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef UTIL_BIT_MASK_2010_06_13_H_
#define UTIL_BIT_MASK_2010_06_13_H_
#ifndef UTIL_BIT_MASK_2010_06_13_H
#define UTIL_BIT_MASK_2010_06_13_H

#include <limits>

namespace util
{
template<typename data_type,
const unsigned bit_pos,
const unsigned bit_cnt>
const unsigned BitPos,
const unsigned BitCnt>
struct bit_mask_multi_value
{
private:
// This bit mask contains bit_cnt continuous bits starting at bit_pos.

static constexpr unsigned bit_pos = BitPos;
static constexpr unsigned bit_cnt = BitCnt;

// Ensure that the data_type is an integer type.
static_assert(std::numeric_limits<data_type>::is_integer == true,
"the data_type of the bit_mask template must be an integer type");
Expand All @@ -28,18 +32,29 @@
"the data_type of the bit_mask template must be unsigned");

// Ensure that the requested bit mask is in range.
static_assert((bit_pos + bit_cnt) <= unsigned(std::numeric_limits<data_type>::digits),
static_assert((bit_pos + bit_cnt) <= unsigned { std::numeric_limits<data_type>::digits },
"the requested bit_mask value exceeds the maximum value of the data_type");

static const data_type value = static_cast<data_type>(static_cast<data_type>(static_cast<data_type>(~static_cast<data_type>(0U)) >> (std::numeric_limits<data_type>::digits - (bit_cnt + 1U))) << bit_pos);
public:
static constexpr data_type value =
static_cast<data_type>
(
static_cast<data_type>
(
static_cast<data_type>(~static_cast<data_type>(0U)) >> static_cast<unsigned>(static_cast<unsigned>(std::numeric_limits<data_type>::digits) - (bit_cnt + 1U))
) << bit_pos
);
};

template<typename data_type,
const unsigned bit_pos>
struct bit_mask_multi_value<data_type, bit_pos, 1U>
const unsigned BitPos>
struct bit_mask_multi_value<data_type, BitPos, 1U>
{
private:
// This bit mask contains one bit at bit_pos.

static constexpr unsigned bit_pos = BitPos;

// Ensure that the data_type is an integer type.
static_assert(std::numeric_limits<data_type>::is_integer == true,
"the data_type of the bit_mask template must be an integer type");
Expand All @@ -52,15 +67,19 @@
static_assert((bit_pos + 1) <= unsigned(std::numeric_limits<data_type>::digits),
"the requested bit_mask value exceeds the maximum value of the data_type");

static const data_type value = static_cast<data_type>(static_cast<data_type>(1U) << bit_pos);
public:
static constexpr data_type value = static_cast<data_type>(static_cast<data_type>(1U) << bit_pos);
};

template<typename data_type,
const unsigned bit_pos>
const unsigned BitPos>
struct bit_mask_single_value
{
private:
// This bit mask contains one bit at bit_pos.

static constexpr unsigned bit_pos = BitPos;

// Ensure that the data_type is an integer type.
static_assert(std::numeric_limits<data_type>::is_integer == true,
"the data_type of the bit_mask template must be an integer type");
Expand All @@ -73,8 +92,9 @@
static_assert((bit_pos + 1) <= unsigned(std::numeric_limits<data_type>::digits),
"the requested bit_mask value exceeds the maximum value of the data_type");

public:
static const data_type value = static_cast<data_type>(static_cast<data_type>(1U) << bit_pos);
};
}

#endif // UTIL_BIT_MASK_2010_06_13_H_
#endif // UTIL_BIT_MASK_2010_06_13_H
Loading

0 comments on commit c8c4e7f

Please sign in to comment.