From a86a53843f82e4d6ca2f2e1437824495acad2712 Mon Sep 17 00:00:00 2001 From: Merry Date: Tue, 19 Apr 2022 16:27:03 +0100 Subject: [PATCH] mcl: Bugfixes --- CMakeLists.txt | 2 +- include/mcl/bit/bit_count.hpp | 2 +- include/mcl/bit/bit_field.hpp | 14 +++++++++++--- include/mcl/bitsizeof.hpp | 1 + include/mcl/concepts/bit_integral.hpp | 2 +- include/mcl/concepts/is_any_of.hpp | 2 +- include/mcl/container/intrusive_list.hpp | 4 ++-- include/mcl/macro/anonymous_variable.hpp | 2 ++ include/mcl/scope_exit.hpp | 2 +- 9 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 392fd50..c1c28f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/mcl/bit/bit_count.hpp b/include/mcl/bit/bit_count.hpp index d4ac628..c08abd0 100644 --- a/include/mcl/bit/bit_count.hpp +++ b/include/mcl/bit/bit_count.hpp @@ -14,7 +14,7 @@ namespace mcl::bit { template inline size_t count_ones(T x) { - return std::bitset>(x).count(); + return std::bitset>(x).count(); } template diff --git a/include/mcl/bit/bit_field.hpp b/include/mcl/bit/bit_field.hpp index 5ea5f9f..e4fca8e 100644 --- a/include/mcl/bit/bit_field.hpp +++ b/include/mcl/bit/bit_field.hpp @@ -19,7 +19,7 @@ constexpr T ones() { if constexpr (count == 0) { return 0; } else { - return ~static_cast(0) >> (bitsizeof - count); + return static_cast(~static_cast(0)) >> (bitsizeof - 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 constexpr T replicate_element(T value) { - static_assert(element_size > bitsizeof, "element_size is too large"); + static_assert(element_size <= bitsizeof, "element_size is too large"); static_assert(bitsizeof % element_size == 0, "bitsize of T not divisible by element_size"); if constexpr (element_size == bitsizeof) { @@ -175,10 +175,18 @@ constexpr T replicate_element(T value) { } } +/// Replicate an element of type U across a value of type T. +template +constexpr T replicate_element(T value) { + static_assert(bitsizeof <= bitsizeof, "element_size is too large"); + + return replicate_element, T>(value); +} + /// Replicate an element across a value of type T. template constexpr T replicate_element(size_t element_size, T value) { - ASSERT_MSG(element_size > bitsizeof, "element_size is too large"); + ASSERT_MSG(element_size <= bitsizeof, "element_size is too large"); ASSERT_MSG(bitsizeof % element_size == 0, "bitsize of T not divisible by element_size"); if (element_size == bitsizeof) { diff --git a/include/mcl/bitsizeof.hpp b/include/mcl/bitsizeof.hpp index a5e76bd..5d28f59 100644 --- a/include/mcl/bitsizeof.hpp +++ b/include/mcl/bitsizeof.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include namespace mcl { diff --git a/include/mcl/concepts/bit_integral.hpp b/include/mcl/concepts/bit_integral.hpp index 412bb4c..caddc05 100644 --- a/include/mcl/concepts/bit_integral.hpp +++ b/include/mcl/concepts/bit_integral.hpp @@ -11,6 +11,6 @@ namespace mcl { /// Integral upon which bit operations can be safely performed. template -concept BitIntegral = IsAnyOf; +concept BitIntegral = IsAnyOf; } // namespace mcl diff --git a/include/mcl/concepts/is_any_of.hpp b/include/mcl/concepts/is_any_of.hpp index 0dab6f4..3e6593d 100644 --- a/include/mcl/concepts/is_any_of.hpp +++ b/include/mcl/concepts/is_any_of.hpp @@ -4,7 +4,7 @@ #pragma once -#include "mcl/same_as.hpp" +#include "mcl/concepts/same_as.hpp" namespace mcl { diff --git a/include/mcl/container/intrusive_list.hpp b/include/mcl/container/intrusive_list.hpp index 2d80c85..b757f21 100644 --- a/include/mcl/container/intrusive_list.hpp +++ b/include/mcl/container/intrusive_list.hpp @@ -39,13 +39,13 @@ template class intrusive_list_sentinel final : public intrusive_list_node { using intrusive_list_node::next; using intrusive_list_node::prev; - using intrusive_list_node::is_sentinel; + using intrusive_list_node::is_sentinel_; public: intrusive_list_sentinel() { next = this; prev = this; - is_sentinel = true; + is_sentinel_ = true; } }; diff --git a/include/mcl/macro/anonymous_variable.hpp b/include/mcl/macro/anonymous_variable.hpp index eca428d..09cd48a 100644 --- a/include/mcl/macro/anonymous_variable.hpp +++ b/include/mcl/macro/anonymous_variable.hpp @@ -4,6 +4,8 @@ #pragma once +#include + #ifdef __COUNTER__ # define ANONYMOUS_VARIABLE(str) CONCATENATE_TOKENS(str, __COUNTER__) #else diff --git a/include/mcl/scope_exit.hpp b/include/mcl/scope_exit.hpp index 708c97b..d6d11ed 100644 --- a/include/mcl/scope_exit.hpp +++ b/include/mcl/scope_exit.hpp @@ -8,7 +8,7 @@ #include #include -#include "mcl/(.*).hpp" +#include namespace mcl::detail {