Skip to content

Commit

Permalink
C++17 now required
Browse files Browse the repository at this point in the history
Exposing some niebloids, also refactored implementation a lot
  • Loading branch information
OleErikPeistorpet committed Sep 29, 2023
1 parent 1e7d826 commit 297348f
Show file tree
Hide file tree
Showing 33 changed files with 569 additions and 645 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
cpp_standard: 17
- os: ubuntu-20.04
gcc_version: 8
cpp_standard: 14
cpp_standard: 17
mem_bound_debug: on
- os: ubuntu-20.04
gcc_version: 9
Expand All @@ -39,11 +39,12 @@ jobs:
gcc_version: 12
cpp_standard: 20
- os: macos-latest
cpp_standard: 14
cpp_standard: 17
mem_bound_debug: on
exclude:
- os: macos-latest
cpp_standard: 17
mem_bound_debug: off

steps:
- if: runner.os == 'Linux'
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = OE-Lib
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.4
PROJECT_NUMBER = 3.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Obscure Efficient Library (v2)
# Obscure Efficient Library

A cross-platform, very fast substitute for C++ std::vector (and std::copy) with a range-based interface.

Features relocation optimizations similar to [Folly fbvector](https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md#object-relocation) and UnrealEngine TArray.

The library is distributed under the Boost Software License, and is header only, just include and go.

C++14 is required. Supported compilers:
* Visual Studio 2017 and later
* GCC 5 and later
* Clang (tested regularly, but minimum version is unknown)
C++17 is required. Oldest supported compilers:
* Visual Studio 2017 (15.8)
* GCC 7
* Clang 5

### Append

Expand Down
8 changes: 4 additions & 4 deletions allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct allocator

namespace _detail
{
constexpr size_t defaultAlign =
inline constexpr size_t defaultAlign =
#if defined __STDCPP_DEFAULT_NEW_ALIGNMENT__
__STDCPP_DEFAULT_NEW_ALIGNMENT__;
#elif _WIN64 or defined __x86_64__ // then assuming 16 byte aligned from malloc
Expand All @@ -67,7 +67,7 @@ namespace _detail
alignof(std::max_align_t);
#endif

constexpr auto * allocFailMsg = "No memory oel::allocator";
inline constexpr auto allocFailMsg = "No memory oel::allocator";

struct BadAlloc
{
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace _detail
{
void * operator()(size_t const nBytes) const
{
OEL_CONST_COND if (Align > defaultAlign)
if constexpr (Align > defaultAlign)
{
void * p = std::malloc(nBytes + Align);
return AlignAndStore<Align>(p);
Expand All @@ -117,7 +117,7 @@ namespace _detail

void * operator()(size_t const nBytes) const
{
OEL_CONST_COND if (Align > defaultAlign)
if constexpr (Align > defaultAlign)
{
void * p = old ?
static_cast<void **>(old)[-1] :
Expand Down
11 changes: 4 additions & 7 deletions auxi/allocate_with_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@

#include <cstdint> // for uintptr_t

namespace oel
{
namespace _detail

namespace oel::_detail
{
struct DebugAllocationHeader
{
std::uintptr_t id;
size_t nObjects;
};

constexpr DebugAllocationHeader headerNoAllocation{0, 0};
inline constexpr DebugAllocationHeader headerNoAllocation{};

#define OEL_DEBUG_HEADER_OF(ptr) ( (DebugAllocationHeader *)static_cast<void *>(ptr) - 1)
#define OEL_DEBUG_HEADER_OF_C(ptr) ((const DebugAllocationHeader *)static_cast<const void *>(ptr) - 1)
Expand Down Expand Up @@ -119,6 +118,4 @@ namespace _detail
Ptr end;
Ptr reservEnd;
};
}

} // namespace oel
}
49 changes: 17 additions & 32 deletions auxi/contiguous_iterator_to_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
namespace oel
{

//! If an IteratorSource range can be copied to an IteratorDest range with memmove, is-a true_type, else false_type
template< typename IteratorDest, typename IteratorSource >
struct can_memmove_with;


#if __cpp_lib_concepts >= 201907
template< std::contiguous_iterator T >
constexpr auto to_pointer_contiguous(T it) noexcept { return std::to_address(it); }

constexpr auto to_pointer_contiguous(std::contiguous_iterator auto it) noexcept
{
return std::to_address(it);
}
#else
namespace _detail
{
Expand Down Expand Up @@ -55,24 +51,16 @@ struct can_memmove_with;
constexpr T * to_pointer_contiguous(std::__wrap_iter<T *> it) noexcept { return it.base(); }

#elif _CPPLIB_VER
#if _MSVC_STL_UPDATE < 201805
#define OEL_UNWRAP(iter) _Unchecked(iter)
#else
#define OEL_UNWRAP(iter) iter._Unwrapped()
#endif

template< typename ContiguousIterator,
enable_if
< std::is_same<
decltype( OEL_UNWRAP(ContiguousIterator{}) ),
typename ContiguousIterator::pointer >::value
enable_if<
std::is_same_v< decltype(ContiguousIterator{}._Unwrapped()),
typename ContiguousIterator::pointer >
> = 0
>
constexpr auto to_pointer_contiguous(const ContiguousIterator & it) noexcept
{
return _detail::ToAddress(OEL_UNWRAP(it));
return _detail::ToAddress(it._Unwrapped());
}
#undef OEL_UNWRAP
#endif
#endif

Expand All @@ -81,12 +69,8 @@ constexpr auto to_pointer_contiguous(std::move_iterator<Iterator> it) noexcept
-> decltype( to_pointer_contiguous(it.base()) )
{ return to_pointer_contiguous(it.base()); }



////////////////////////////////////////////////////////////////////////////////



namespace _detail
{
template< typename Range >
Expand All @@ -99,7 +83,7 @@ namespace _detail
> = 0 >
constexpr auto Size(Range && r, None...)
-> decltype(end(r) - begin(r))
{ return end(r) - begin(r); }
{ return end(r) - begin(r); }



Expand All @@ -114,12 +98,13 @@ namespace _detail
false_type CanMemmoveWith(...);
}

} // namespace oel

//! @cond FALSE

//! Is true if an IteratorSource range can be copied to an IteratorDest range with memmove
template< typename IteratorDest, typename IteratorSource >
struct oel::can_memmove_with :
decltype( _detail::CanMemmoveWith(std::declval<IteratorDest>(),
std::declval<IteratorSource>()) ) {};
//! @endcond
inline constexpr bool can_memmove_with =
decltype(
_detail::CanMemmoveWith(std::declval<IteratorDest>(),
std::declval<IteratorSource>())
)::value;

} // namespace oel
19 changes: 7 additions & 12 deletions auxi/detail_forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

#include "type_traits.h"

namespace oel
{
namespace _detail

namespace oel::_detail
{
// Note: false for arrays, they aren't copy/move constructible
template< typename T, typename SansRef, bool IsConst >
Expand All @@ -21,28 +20,24 @@ namespace _detail
(std::is_move_constructible_v<SansRef> and !IsConst) ) // !IsConst implies rvalue due to check in ForwardT
and sizeof(SansRef) <= 2 * sizeof(int)
#else
std::is_trivially_copy_constructible<SansRef>::value and std::is_trivially_destructible<SansRef>::value
std::is_trivially_copy_constructible_v<SansRef> and std::is_trivially_destructible_v<SansRef>
and sizeof(SansRef) <= 2 * sizeof(void *)
#endif
> {};

template< typename T,
typename SansRef = std::remove_reference_t<T>,
bool IsConst = std::is_const<SansRef>::value
bool IsConst = std::is_const_v<SansRef>
>
using ForwardT =
std::conditional_t<
conjunctionV<
std::conjunction_v<
// Forwarding a function or mutable lvalue reference by value would break
bool_constant<
(!std::is_lvalue_reference<T>::value or IsConst)
and !std::is_function<SansRef>::value
>,
bool_constant< !std::is_lvalue_reference_v<T> or IsConst >,
std::negation< std::is_function<SansRef> >,
PassByValueIsBetter<T, SansRef, IsConst>
>,
std::remove_cv_t<SansRef>,
T &&
>;
}

}
13 changes: 2 additions & 11 deletions auxi/dynarray_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ Ptr to_pointer_contiguous(const dynarray_iterator<Ptr> & it) noexcept { return

} // namespace oel

namespace std
{

template< typename Ptr >
struct pointer_traits< oel::dynarray_iterator<Ptr> >
struct std::pointer_traits< oel::dynarray_iterator<Ptr> >
{
using pointer = oel::dynarray_iterator<Ptr>;
using difference_type = typename pointer::difference_type;
Expand All @@ -207,17 +204,13 @@ struct pointer_traits< oel::dynarray_iterator<Ptr> >
static element_type * to_address(const pointer & it) noexcept { return it._pElem; }
};

}



////////////////////////////////////////////////////////////////////////////////



namespace oel
{
namespace _detail
namespace oel::_detail
{
template< typename Ptr >
dynarray_iterator<Ptr> MakeDynarrayIter(Ptr const pos, Ptr const begin, const void * parent) noexcept
Expand All @@ -231,6 +224,4 @@ namespace _detail
{ return {pos, &_detail::headerNoAllocation, reinterpret_cast<std::uintptr_t>(parent)};
}
}
}

}
Loading

0 comments on commit 297348f

Please sign in to comment.