Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTest online #72

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CMake

on:
push:
branches: [ "dev/**", "alpha" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
env:
unit_test_dir: ${{github.workspace}}/test/catch

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4.2.2
with:
submodules: recursive

- name: Build
uses: threeal/cmake-action@v2.1.0
with:
source-dir: ${{env.unit_test_dir}}

- name: Test
uses: threeal/ctest-action@v1.1.0
with:
# DEBT: Grab "build-dir" from above cmake-action
test-dir: ${{env.unit_test_dir}}/build

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v0.8.2 - DDMMM24

## Added Features

* https://github.com/malachi-iot/estdlib/issues/69 `get<T>(tuple)` now available

## Quality Updates & Bug Fixes

* https://github.com/malachi-iot/estdlib/issues/66 `tuple.visit()` now works with references too

# v0.8.1 - 31OCT24

## Added Features
Expand Down
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Embedded std library (estdlib)
Copyright 2023 Malachi Burke
Embedded std library (estd)
Copyright 2023, 2024 Malachi Burke
32 changes: 15 additions & 17 deletions src/estd/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace estd {

// Shamelessly lifted from https://en.cppreference.com/w/cpp/algorithm/fill_n
template<class OutputIt, class Size, class T>
inline OutputIt fill_n(OutputIt first, Size count, const T& value)
ESTD_CPP_CONSTEXPR(20) OutputIt fill_n(OutputIt first, Size count, const T& value)
{
#if FEATURE_ESTD_ALGORITHM_OPT
return std::fill_n(first, count, value);
Expand Down Expand Up @@ -89,7 +89,7 @@ ForwardIt min_element(ForwardIt first, ForwardIt last,
#endif

template<class InputIt, class OutputIt>
inline OutputIt copy(InputIt first, InputIt last,
ESTD_CPP_CONSTEXPR(20) OutputIt copy(InputIt first, InputIt last,
OutputIt d_first)
{
#if FEATURE_ESTD_ALGORITHM_OPT
Expand All @@ -106,12 +106,16 @@ inline OutputIt copy(InputIt first, InputIt last,
// has a more complex implementation, but unsure why. Maybe they want to avoid incrementing the source
// iterator unnecessarily?
template <class InputIt, class Size, class OutputIt>
inline OutputIt copy_n(InputIt first, Size count, OutputIt result)
ESTD_CPP_CONSTEXPR(20) OutputIt copy_n(InputIt first, Size count, OutputIt result)
{
#if FEATURE_ESTD_ALGORITHM_OPT
return std::copy_n(first, count, result);
#else
while(count--)
*result++ = *first++;

return result;
#endif
}


Expand Down Expand Up @@ -160,26 +164,20 @@ InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
return last;
}

template<class T>
#ifdef FEATURE_CPP_CONSTEXPR_METHOD
constexpr
#endif
const T& clamp( const T& v, const T& lo, const T& hi )
{
return clamp( v, lo, hi, estd::less<T>() );
}


template<class T, class Compare>
#if defined(FEATURE_CPP_CONSTEXPR_METHOD) && !defined(ESP8266)
constexpr
#endif
const T& clamp( const T& v, const T& lo, const T& hi, Compare comp )
ESTD_CPP_CONSTEXPR(17) const T& clamp( const T& v, const T& lo, const T& hi, Compare comp )
{
return assert( !comp(hi, lo) ),
comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}

template<class T>
ESTD_CPP_CONSTEXPR(17) const T& clamp( const T& v, const T& lo, const T& hi )
{
return estd::clamp( v, lo, hi, estd::less<T>() );
}


// UNTESTED
template<class InputIt1, class InputIt2>
#ifdef FEATURE_CPP_CONSTEXPR_METHOD
Expand Down
23 changes: 23 additions & 0 deletions src/estd/internal/macro/c++11_emul.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
#define ESTD_CPP_CONSTEXPR_RET inline
#endif

// Take pages out of GCC playbook
// DEBT: These belong elsewhere, not in c++_emul per se
#if __cplusplus >= 202002L
#define ESTD_CPP20_CONSTEXPR constexpr
#else
#define ESTD_CPP20_CONSTEXPR
#endif

#if __cplusplus >= 201703L
#define ESTD_CPP17_CONSTEXPR constexpr
#else
#define ESTD_CPP17_CONSTEXPR
#endif

#if __cplusplus >= 201402L
#define ESTD_CPP14_CONSTEXPR constexpr
#else
#define ESTD_CPP14_CONSTEXPR
#endif


#define ESTD_CPP_CONSTEXPR(v) ESTD_CPP ## v ## _CONSTEXPR

#if __cpp_ref_qualifiers
#define ESTD_CPP_REFQ &
#else
Expand Down
2 changes: 1 addition & 1 deletion src/estd/internal/macro/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Assistance to define typical "typedef T value_type" and friends
#define ESTD_CPP_STD_VALUE_TYPE(T) \
typedef T value_type; \
typedef T value_type; \
typedef value_type& reference; \
typedef const value_type& const_reference; \
typedef value_type* pointer; \
Expand Down
2 changes: 1 addition & 1 deletion src/estd/internal/raw/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct type_identity { typedef T type; };
template<class T, T v>
struct integral_constant
{
static CONSTEXPR T value = v;
static constexpr T value = v;
typedef T value_type;
typedef integral_constant type; // using injected-class-name

Expand Down
8 changes: 5 additions & 3 deletions src/estd/internal/raw/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ struct in_place_conditional_t : in_place_tag {};

struct in_place_t : internal::in_place_tag
{

constexpr explicit in_place_t() = default;
};

template <class T>
struct in_place_type_t : internal::in_place_tag
{

constexpr explicit in_place_type_t() = default;
};

template <size_t>
struct in_place_index_t : internal::in_place_tag
{};
{
constexpr explicit in_place_index_t() = default;
};

}
1 change: 0 additions & 1 deletion src/estd/internal/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "tuple/get.h" // DEBT: Must precede 'visitor.h' likely due to probable lack of 'get' forward declaration
#include "tuple/sparse.h"

// EXPERIMENTAL
#include "variadic/visitor.h"

namespace estd { namespace internal {
Expand Down
30 changes: 28 additions & 2 deletions src/estd/internal/tuple/get.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "fwd.h"
#include "../variadic/type_sequence.h"

namespace estd {

Expand Down Expand Up @@ -64,14 +65,14 @@ constexpr typename tuple_element<index, tuple<Types...> >::const_valref_type get
}

template<int index, bool sparse, typename... Types>
inline typename tuple_element<index, tuple<Types...> >::valref_type get(
ESTD_CPP_CONSTEXPR(20) typename tuple_element<index, tuple<Types...> >::valref_type get(
internal::tuple<sparse, Types...>& t)
{
return internal::GetImpl<sparse, index, Types...>::value(t);
}

template<int index, bool sparse, typename... Types>
inline tuple_element_t<index, tuple<Types...> >&& get(internal::tuple<sparse, Types...>&& t)
ESTD_CPP_CONSTEXPR(20) tuple_element_t<index, tuple<Types...> >&& get(internal::tuple<sparse, Types...>&& t)
{
return internal::GetImpl<sparse, index, Types...>::value(std::move(t));
}
Expand All @@ -82,4 +83,29 @@ constexpr tuple_element_t<index, tuple<Types...> >&& get(const internal::tuple<s
return internal::GetImpl<sparse, index, Types...>::value(t);
}

template <class T, bool sparse, typename... Types>
ESTD_CPP_CONSTEXPR(14) T& get(internal::tuple<sparse, Types...>& t)
{
return get<internal::single_index_of_type<T, Types...>::index>(t);
}


template <class T, bool sparse, typename... Types>
ESTD_CPP_CONSTEXPR(14) T&& get(internal::tuple<sparse, Types...>&& t)
{
return get<internal::single_index_of_type<T, Types...>::index>(t);
}

template <class T, bool sparse, typename... Types>
constexpr const T& get(const internal::tuple<sparse, Types...>& t)
{
return get<internal::single_index_of_type<T, Types...>::index>(t);
}

template <class T, bool sparse, typename... Types>
constexpr const T&& get(const internal::tuple<sparse, Types...>&& t)
{
return get<internal::single_index_of_type<T, Types...>::index>(t);
}

}
32 changes: 32 additions & 0 deletions src/estd/internal/variadic/type_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,38 @@ struct get_type_at_index<pos, T, Types...> :
{
};

// DEBT: Try to consolidate with "get_index_finder" and "selector"

// defaults to zero matches (value == 0)
template <class Matching, class ...Types>
struct detail_get_index_of_type : integral_constant<int, 0> { };

// keeps looking during no match
template <class Matching, class T, class ...Types>
struct detail_get_index_of_type<Matching, T, Types...> : detail_get_index_of_type<Matching, Types...> {};

// increments match counter (++value), finds first occurence of Match but continues
template <class Matched, class ...Types>
struct detail_get_index_of_type<Matched, Matched, Types...> :
integral_constant<int, detail_get_index_of_type<Matched, Types...>::value + 1>
{
static constexpr unsigned index = sizeof ...(Types);
};

template <class Match, class ...Types>
struct first_index_of_type
{
using detail = detail_get_index_of_type<Match, Types...>;

static constexpr unsigned matches = detail::value;
static constexpr unsigned index = (sizeof...(Types) - 1) - detail::index;
};

template <class Match, class ...Types>
struct single_index_of_type : first_index_of_type<Match, Types...>
{
static_assert(first_index_of_type<Match, Types...>::matches == 1, "One and only one match is permitted");
};

template <class ...Types>
struct type_sequence_accessor
Expand Down
Loading