mcl: Bugfixes

This commit is contained in:
Merry 2022-04-19 16:27:03 +01:00
parent 215182d9a7
commit a86a53843f
9 changed files with 21 additions and 10 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
include(GNUInstallDirs)
project(mcl LANGUAGES CXX VERSION 0.1.2)
project(mcl LANGUAGES CXX VERSION 0.1.3)
# Project options
option(MCL_WARNINGS_AS_ERRORS "Warnings as errors" ON)

View File

@ -14,7 +14,7 @@ namespace mcl::bit {
template<BitIntegral T>
inline size_t count_ones(T x) {
return std::bitset<bitsizeof<Integral>>(x).count();
return std::bitset<bitsizeof<T>>(x).count();
}
template<BitIntegral T>

View File

@ -19,7 +19,7 @@ constexpr T ones() {
if constexpr (count == 0) {
return 0;
} else {
return ~static_cast<T>(0) >> (bitsizeof<T> - count);
return static_cast<T>(~static_cast<T>(0)) >> (bitsizeof<T> - count);
}
}
@ -165,7 +165,7 @@ constexpr T sign_extend(size_t bit_count, T value) {
/// Replicate an element across a value of type T.
template<size_t element_size, BitIntegral T>
constexpr T replicate_element(T value) {
static_assert(element_size > bitsizeof<T>, "element_size is too large");
static_assert(element_size <= bitsizeof<T>, "element_size is too large");
static_assert(bitsizeof<T> % element_size == 0, "bitsize of T not divisible by element_size");
if constexpr (element_size == bitsizeof<T>) {
@ -175,10 +175,18 @@ constexpr T replicate_element(T value) {
}
}
/// Replicate an element of type U across a value of type T.
template<BitIntegral U, BitIntegral T>
constexpr T replicate_element(T value) {
static_assert(bitsizeof<U> <= bitsizeof<T>, "element_size is too large");
return replicate_element<bitsizeof<U>, T>(value);
}
/// Replicate an element across a value of type T.
template<BitIntegral T>
constexpr T replicate_element(size_t element_size, T value) {
ASSERT_MSG(element_size > bitsizeof<T>, "element_size is too large");
ASSERT_MSG(element_size <= bitsizeof<T>, "element_size is too large");
ASSERT_MSG(bitsizeof<T> % element_size == 0, "bitsize of T not divisible by element_size");
if (element_size == bitsizeof<T>) {

View File

@ -5,6 +5,7 @@
#pragma once
#include <climits>
#include <cstddef>
namespace mcl {

View File

@ -11,6 +11,6 @@ namespace mcl {
/// Integral upon which bit operations can be safely performed.
template<typename T>
concept BitIntegral = IsAnyOf<T, u8, u16, u32, u64>;
concept BitIntegral = IsAnyOf<T, u8, u16, u32, u64, uptr, size_t>;
} // namespace mcl

View File

@ -4,7 +4,7 @@
#pragma once
#include "mcl/same_as.hpp"
#include "mcl/concepts/same_as.hpp"
namespace mcl {

View File

@ -39,13 +39,13 @@ template<typename T>
class intrusive_list_sentinel final : public intrusive_list_node<T> {
using intrusive_list_node<T>::next;
using intrusive_list_node<T>::prev;
using intrusive_list_node<T>::is_sentinel;
using intrusive_list_node<T>::is_sentinel_;
public:
intrusive_list_sentinel() {
next = this;
prev = this;
is_sentinel = true;
is_sentinel_ = true;
}
};

View File

@ -4,6 +4,8 @@
#pragma once
#include <mcl/macro/concatenate_tokens.hpp>
#ifdef __COUNTER__
# define ANONYMOUS_VARIABLE(str) CONCATENATE_TOKENS(str, __COUNTER__)
#else

View File

@ -8,7 +8,7 @@
#include <type_traits>
#include <utility>
#include "mcl/(.*).hpp"
#include <mcl/macro/anonymous_variable.hpp>
namespace mcl::detail {