From b3538493d895541db37c4401baf82ee5068fda6e Mon Sep 17 00:00:00 2001 From: denzor200 Date: Sun, 25 Apr 2021 23:56:33 +0400 Subject: [PATCH 01/10] Draft for boost::pfr::get_memptr --- include/boost/pfr.hpp | 1 + include/boost/pfr/core_memptr.hpp | 56 ++++++++++++++ include/boost/pfr/detail/align.hpp | 32 ++++++++ include/boost/pfr/detail/core_memptr.hpp | 97 ++++++++++++++++++++++++ include/boost/pfr/detail/memptr_cast.hpp | 30 ++++++++ include/boost/pfr/type_identity.hpp | 22 ++++++ test/run/memptr.cpp | 42 ++++++++++ 7 files changed, 280 insertions(+) create mode 100644 include/boost/pfr/core_memptr.hpp create mode 100644 include/boost/pfr/detail/align.hpp create mode 100644 include/boost/pfr/detail/core_memptr.hpp create mode 100644 include/boost/pfr/detail/memptr_cast.hpp create mode 100644 include/boost/pfr/type_identity.hpp create mode 100644 test/run/memptr.cpp diff --git a/include/boost/pfr.hpp b/include/boost/pfr.hpp index 3eaf421b..360589d6 100644 --- a/include/boost/pfr.hpp +++ b/include/boost/pfr.hpp @@ -10,6 +10,7 @@ /// Includes all the Boost.PFR headers #include +#include #include #include #include diff --git a/include/boost/pfr/core_memptr.hpp b/include/boost/pfr/core_memptr.hpp new file mode 100644 index 00000000..2ecbc913 --- /dev/null +++ b/include/boost/pfr/core_memptr.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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 BOOST_PFR_CORE_MEMPTR_HPP +#define BOOST_PFR_CORE_MEMPTR_HPP +#pragma once + +#include + +#include + +#include +#include + +#include +#include // metaprogramming stuff + +#include +#include + +/// \file boost/pfr/core_memptr.hpp +/// Contains all the basic interfaces for working with member pointers of some structure \forcedlink{get_memptr}, and others. +/// +/// \b Synopsis: + +namespace boost { namespace pfr { + +/// \brief Returns member pointer to a field with index `I` in some \aggregate with type 'T'. +/// +/// \b Example: +/// \code +/// struct my_struct { int i, short s; }; +/// my_struct s {10, 11}; +/// assert(boost::pfr::get_memptr<0>(s) == &my_struct::i); +/// auto memptr = boost::pfr::get_memptr<1>(s); +/// s.*memptr = 0; +/// \endcode +template +inline auto get_memptr(boost::pfr::type_identity) noexcept +{ + return detail::sequence_tuple::get( detail::tie_as_memptrs_tuple() ); +} + +/// \overload get_memptr +template +inline auto get_memptr(const T&) noexcept +{ + // TODO: test it without default constructor + return get_memptr(boost::pfr::type_identity{}); +} + +}} // namespace boost::pfr + +#endif // BOOST_PFR_CORE_MEMPTR_HPP diff --git a/include/boost/pfr/detail/align.hpp b/include/boost/pfr/detail/align.hpp new file mode 100644 index 00000000..e5514358 --- /dev/null +++ b/include/boost/pfr/detail/align.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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 BOOST_PFR_DETAIL_ALIGN_HPP +#define BOOST_PFR_DETAIL_ALIGN_HPP +#pragma once + +#include +#include // for std::size_t + +namespace boost { namespace pfr { namespace detail { + + constexpr std::size_t align_offset(std::size_t alignment, std::size_t size, std::size_t& offset, std::size_t& space) noexcept + { + //BOOST_ASSERT(boost::alignment::detail::is_alignment(alignment)); TODO enable + if (size <= space) { + std::size_t p = ~(alignment - 1) & (offset + alignment - 1); + std::size_t n = p - offset; + if (n <= space - size) { + offset = p; + space -= n; + return p; + } + } + return (size_t)-1; + } + +}}} // namespace boost::pfr::detail + +#endif // BOOST_PFR_DETAIL_ALIGN_HPP diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp new file mode 100644 index 00000000..226b81f1 --- /dev/null +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -0,0 +1,97 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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 BOOST_PFR_DETAIL_CORE_MEMPTR_HPP +#define BOOST_PFR_DETAIL_CORE_MEMPTR_HPP +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +// Each core_memptr provides `boost::pfr::detail::tie_as_memptrs_tuple` and +// `boost::pfr::detail::for_each_memptr_dispatcher` functions. +// +// The whole memptr's functionality in PFR library is build on top of those two functions. + +namespace boost { namespace pfr { namespace detail { + +template +constexpr auto make_sequence_tuple(Args... args) noexcept { + return sequence_tuple::tuple{ args... }; +} + +template +using tuple_element_ = sequence_tuple::tuple_element()) ) >; + +template +using tuple_memptr_t = typename detail::tuple_element_::type T::*; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template +constexpr std::size_t tie_as_offsets_tuple_impl_apply(I i, std::size_t& offset, std::size_t& space) noexcept +{ + using element_type = typename detail::tuple_element_::type; + std::size_t aligned = detail::align_offset(alignof(element_type), sizeof(element_type), offset, space); + offset += sizeof(element_type); + space -= sizeof(element_type); + return aligned; +} + +template +constexpr auto tie_as_offsets_tuple_impl(std::index_sequence, std::size_t& offset, std::size_t& space) noexcept +{ + const std::size_t v[] = { ( + tie_as_offsets_tuple_impl_apply(size_t_{}, offset, space) + )... }; + return detail::make_sequence_tuple( v[I]... ); +} + +template +constexpr auto tie_as_offsets_tuple_impl(std::index_sequence<>, std::size_t& offset, std::size_t& space) noexcept +{ + // TODO: test for empty structure + (void)offset; + (void)space; + return detail::make_sequence_tuple(); +} + +template +constexpr auto tie_as_offsets_tuple() noexcept +{ + // TODO: discard structures with non-standard alignment and bit fields + std::size_t offset = 0; + std::size_t space = sizeof(T); + + return tie_as_offsets_tuple_impl(detail::make_index_sequence()>{}, offset, space); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template +inline auto tie_as_memptrs_tuple_impl(std::index_sequence) noexcept +{ + constexpr auto offsets = tie_as_offsets_tuple(); + return detail::make_sequence_tuple( detail::memptr_cast>(sequence_tuple::get(offsets))... ); +} + +template +inline auto tie_as_memptrs_tuple() noexcept { + static_assert( + !std::is_union::value, + "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info." + ); + + return tie_as_memptrs_tuple_impl(detail::make_index_sequence()>{}); +} + +}}} // namespace boost::pfr::detail + +#endif // BOOST_PFR_DETAIL_CORE_MEMPTR_HPP diff --git a/include/boost/pfr/detail/memptr_cast.hpp b/include/boost/pfr/detail/memptr_cast.hpp new file mode 100644 index 00000000..6a6a9a05 --- /dev/null +++ b/include/boost/pfr/detail/memptr_cast.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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 BOOST_PFR_DETAIL_MEMPTR_CAST_HPP +#define BOOST_PFR_DETAIL_MEMPTR_CAST_HPP +#pragma once + +#include + +namespace boost { namespace pfr { namespace detail { + + template + /*constexpr*/ inline T memptr_cast(std::size_t offset) noexcept + { + // TODO: implement offset checking + // TODO: implement check that T is correct member pointer + static_assert(sizeof(T) == sizeof(std::size_t), "====================> Boost.PFR: Internal error while casting offset to member pointer"); + union { + T memptr; + std::size_t offset_; + }; + offset_ = offset; + return memptr; + } + +}}} // namespace boost::pfr::detail + +#endif // BOOST_PFR_DETAIL_MEMPTR_CAST_HPP diff --git a/include/boost/pfr/type_identity.hpp b/include/boost/pfr/type_identity.hpp new file mode 100644 index 00000000..12ef7e5c --- /dev/null +++ b/include/boost/pfr/type_identity.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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 BOOST_PFR_TYPE_IDENTITY_HPP +#define BOOST_PFR_TYPE_IDENTITY_HPP +#pragma once + +#include + +namespace boost { namespace pfr { + +template< class T > +struct type_identity { + using type = T; +}; + +}} // namespace boost::pfr + + +#endif // BOOST_PFR_TYPE_IDENTITY_HPP diff --git a/test/run/memptr.cpp b/test/run/memptr.cpp new file mode 100644 index 00000000..82c09411 --- /dev/null +++ b/test/run/memptr.cpp @@ -0,0 +1,42 @@ +// Copyright (c) 2021 Denis Mikhailov +// +// 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) + +#include +#include + +struct Foo +{ + char ch; + short id; + short opt; + int value; +}; + +int main() { + + auto ch_memptr = boost::pfr::get_memptr<0>(boost::pfr::type_identity{}); + auto id_memptr = boost::pfr::get_memptr<1>(boost::pfr::type_identity{}); + auto opt_memptr = boost::pfr::get_memptr<2>(boost::pfr::type_identity{}); + auto value_memptr = boost::pfr::get_memptr<3>(boost::pfr::type_identity{}); + + BOOST_TEST_EQ(ch_memptr, &Foo::ch); + BOOST_TEST_EQ(id_memptr, &Foo::id); + BOOST_TEST_EQ(opt_memptr, &Foo::opt); + BOOST_TEST_EQ(value_memptr, &Foo::value); + + auto obj = Foo{}; + + obj.*ch_memptr = 'c'; + obj.*id_memptr = 100; + obj.*opt_memptr = 200; + obj.*value_memptr = 3000; + + BOOST_TEST_EQ(obj.ch, 'c'); + BOOST_TEST_EQ(obj.id, 100); + BOOST_TEST_EQ(obj.opt, 200); + BOOST_TEST_EQ(obj.value, 3000); + + return boost::report_errors(); +} From 33291560d20eded77dd4a751605e69004e759770 Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Tue, 27 Apr 2021 00:01:22 +0400 Subject: [PATCH 02/10] Update core_memptr.hpp --- include/boost/pfr/detail/core_memptr.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp index 226b81f1..e42a76c2 100644 --- a/include/boost/pfr/detail/core_memptr.hpp +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -48,10 +48,7 @@ constexpr std::size_t tie_as_offsets_tuple_impl_apply(I i, std::size_t& offset, template constexpr auto tie_as_offsets_tuple_impl(std::index_sequence, std::size_t& offset, std::size_t& space) noexcept { - const std::size_t v[] = { ( - tie_as_offsets_tuple_impl_apply(size_t_{}, offset, space) - )... }; - return detail::make_sequence_tuple( v[I]... ); + return detail::make_sequence_tuple( tie_as_offsets_tuple_impl_apply(size_t_{}, offset, space)... ); } template From a330973807e0fb1358457494a500493b7d6997b9 Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Tue, 27 Apr 2021 13:11:36 +0400 Subject: [PATCH 03/10] Update core_memptr.hpp --- include/boost/pfr/detail/core_memptr.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp index e42a76c2..c520d6cf 100644 --- a/include/boost/pfr/detail/core_memptr.hpp +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -33,6 +33,7 @@ using tuple_element_ = sequence_tuple::tuple_element using tuple_memptr_t = typename detail::tuple_element_::type T::*; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template From b48f5964e5c0dc6cb2d72fa7ff31796df1ee5503 Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Tue, 27 Apr 2021 22:52:54 +0400 Subject: [PATCH 04/10] Update core_memptr.hpp --- include/boost/pfr/detail/core_memptr.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp index c520d6cf..123c319b 100644 --- a/include/boost/pfr/detail/core_memptr.hpp +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -77,7 +77,7 @@ template inline auto tie_as_memptrs_tuple_impl(std::index_sequence) noexcept { constexpr auto offsets = tie_as_offsets_tuple(); - return detail::make_sequence_tuple( detail::memptr_cast>(sequence_tuple::get(offsets))... ); + return detail::make_sequence_tuple( detail::memptr_cast>(size_t_(offsets))>{}... ); } template From e69f265112d80b77eb282244bd4b26fcca4e9f8e Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Tue, 27 Apr 2021 22:55:45 +0400 Subject: [PATCH 05/10] Update memptr_cast.hpp --- include/boost/pfr/detail/memptr_cast.hpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/include/boost/pfr/detail/memptr_cast.hpp b/include/boost/pfr/detail/memptr_cast.hpp index 6a6a9a05..1387e19e 100644 --- a/include/boost/pfr/detail/memptr_cast.hpp +++ b/include/boost/pfr/detail/memptr_cast.hpp @@ -8,20 +8,29 @@ #pragma once #include +#include +#include namespace boost { namespace pfr { namespace detail { - template - /*constexpr*/ inline T memptr_cast(std::size_t offset) noexcept + constexpr std::uint8_t unsigned_by_size(size_t_<1>) noexcept { return 0; } + constexpr std::uint16_t unsigned_by_size(size_t_<2>) noexcept { return 0; } + constexpr std::uint32_t unsigned_by_size(size_t_<4>) noexcept { return 0; } + constexpr std::uint64_t unsigned_by_size(size_t_<8>) noexcept { return 0; } + + template + inline T memptr_cast(size_t_ offset) { - // TODO: implement offset checking - // TODO: implement check that T is correct member pointer - static_assert(sizeof(T) == sizeof(std::size_t), "====================> Boost.PFR: Internal error while casting offset to member pointer"); + using raw_type = decltype(unsigned_by_size(size_t_{ })); + + static_assert(sizeof(raw_type) <= sizeof(std::size_t), "====================> Boost.PFR: Internal error while casting offset to member pointer."); + static_assert(decltype(offset)::value <= (std::size_t)std::numeric_limits::max(), "====================> Boost.PFR: Internal error while casting offset to member pointer: overflow was detected"); + union { T memptr; - std::size_t offset_; + raw_type offset_; }; - offset_ = offset; + offset_ = static_cast(offset); return memptr; } From 0ff147526567556d9793e2c62c55d7968fcdd4d6 Mon Sep 17 00:00:00 2001 From: denzor200 Date: Tue, 27 Apr 2021 23:11:34 +0400 Subject: [PATCH 06/10] fix --- include/boost/pfr/detail/core_memptr.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp index 123c319b..20cd10de 100644 --- a/include/boost/pfr/detail/core_memptr.hpp +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -77,7 +77,7 @@ template inline auto tie_as_memptrs_tuple_impl(std::index_sequence) noexcept { constexpr auto offsets = tie_as_offsets_tuple(); - return detail::make_sequence_tuple( detail::memptr_cast>(size_t_(offsets))>{}... ); + return detail::make_sequence_tuple( detail::memptr_cast>(size_t_(offsets)>{})... ); } template From 89b9aa4d058c7357fba8a19dfca6702253d1e5fc Mon Sep 17 00:00:00 2001 From: denzor200 Date: Tue, 27 Apr 2021 23:37:04 +0400 Subject: [PATCH 07/10] fix --- include/boost/pfr/detail/memptr_cast.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/boost/pfr/detail/memptr_cast.hpp b/include/boost/pfr/detail/memptr_cast.hpp index 1387e19e..736a3c98 100644 --- a/include/boost/pfr/detail/memptr_cast.hpp +++ b/include/boost/pfr/detail/memptr_cast.hpp @@ -13,7 +13,7 @@ namespace boost { namespace pfr { namespace detail { - constexpr std::uint8_t unsigned_by_size(size_t_<1>) noexcept { return 0; } + constexpr std::uint8_t unsigned_by_size(size_t_<1>) noexcept { return 0; } constexpr std::uint16_t unsigned_by_size(size_t_<2>) noexcept { return 0; } constexpr std::uint32_t unsigned_by_size(size_t_<4>) noexcept { return 0; } constexpr std::uint64_t unsigned_by_size(size_t_<8>) noexcept { return 0; } @@ -23,8 +23,14 @@ namespace boost { namespace pfr { namespace detail { { using raw_type = decltype(unsigned_by_size(size_t_{ })); - static_assert(sizeof(raw_type) <= sizeof(std::size_t), "====================> Boost.PFR: Internal error while casting offset to member pointer."); - static_assert(decltype(offset)::value <= (std::size_t)std::numeric_limits::max(), "====================> Boost.PFR: Internal error while casting offset to member pointer: overflow was detected"); + static_assert( + sizeof(raw_type) <= sizeof(std::size_t), + "====================> Boost.PFR: Internal error while casting offset to member pointer." + ); + static_assert( + decltype(offset)::value <= (std::size_t)std::numeric_limits::max(), + "====================> Boost.PFR: Internal error while casting offset to member pointer: overflow was detected" + ); union { T memptr; From 724775f03dc450ed3add75413ae055e47cf4a01c Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Sun, 2 May 2021 18:11:33 +0400 Subject: [PATCH 08/10] Update memptr_cast.hpp --- include/boost/pfr/detail/memptr_cast.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/pfr/detail/memptr_cast.hpp b/include/boost/pfr/detail/memptr_cast.hpp index 736a3c98..905acc21 100644 --- a/include/boost/pfr/detail/memptr_cast.hpp +++ b/include/boost/pfr/detail/memptr_cast.hpp @@ -28,7 +28,7 @@ namespace boost { namespace pfr { namespace detail { "====================> Boost.PFR: Internal error while casting offset to member pointer." ); static_assert( - decltype(offset)::value <= (std::size_t)std::numeric_limits::max(), + decltype(offset)::value <= (std::size_t)(std::numeric_limits::max)(), "====================> Boost.PFR: Internal error while casting offset to member pointer: overflow was detected" ); From 2636b2e69a4707692b67e3ac25eba40248bc34ac Mon Sep 17 00:00:00 2001 From: denzor200 Date: Sat, 23 Sep 2023 01:10:08 +0300 Subject: [PATCH 09/10] Update copyrights --- include/boost/pfr/core_memptr.hpp | 2 +- include/boost/pfr/detail/align.hpp | 7 ++++++- include/boost/pfr/detail/core_memptr.hpp | 2 +- include/boost/pfr/detail/memptr_cast.hpp | 2 +- include/boost/pfr/type_identity.hpp | 2 +- test/core/run/memptr.cpp | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/boost/pfr/core_memptr.hpp b/include/boost/pfr/core_memptr.hpp index 2ecbc913..478cfe4f 100644 --- a/include/boost/pfr/core_memptr.hpp +++ b/include/boost/pfr/core_memptr.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Denis Mikhailov // // 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) diff --git a/include/boost/pfr/detail/align.hpp b/include/boost/pfr/detail/align.hpp index e5514358..44d0c894 100644 --- a/include/boost/pfr/detail/align.hpp +++ b/include/boost/pfr/detail/align.hpp @@ -1,8 +1,13 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Glen Joseph Fernandes, Denis Mikhailov // // 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) + +// Initial implementation was taken from Boost.Align library by Glen Joseph Fernandes, https://github.com/glenfe +// See https://github.com/boostorg/align/blob/boost-1.83.0/include/boost/align/detail/align.hpp for more details +// + #ifndef BOOST_PFR_DETAIL_ALIGN_HPP #define BOOST_PFR_DETAIL_ALIGN_HPP #pragma once diff --git a/include/boost/pfr/detail/core_memptr.hpp b/include/boost/pfr/detail/core_memptr.hpp index 20cd10de..eac626d1 100644 --- a/include/boost/pfr/detail/core_memptr.hpp +++ b/include/boost/pfr/detail/core_memptr.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Denis Mikhailov // // 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) diff --git a/include/boost/pfr/detail/memptr_cast.hpp b/include/boost/pfr/detail/memptr_cast.hpp index 905acc21..9cd1a463 100644 --- a/include/boost/pfr/detail/memptr_cast.hpp +++ b/include/boost/pfr/detail/memptr_cast.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Denis Mikhailov // // 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) diff --git a/include/boost/pfr/type_identity.hpp b/include/boost/pfr/type_identity.hpp index 12ef7e5c..1ea38355 100644 --- a/include/boost/pfr/type_identity.hpp +++ b/include/boost/pfr/type_identity.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Denis Mikhailov // // 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) diff --git a/test/core/run/memptr.cpp b/test/core/run/memptr.cpp index 82c09411..5adc1688 100644 --- a/test/core/run/memptr.cpp +++ b/test/core/run/memptr.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Denis Mikhailov +// Copyright (c) 2021-2023 Denis Mikhailov // // 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) From 7dcd8904a9bf7f6f3f24c8dd186d9ce738760c74 Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Sat, 18 Nov 2023 16:43:25 +0100 Subject: [PATCH 10/10] Create packed.cpp --- test/core/compile-fail/packed.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/core/compile-fail/packed.cpp diff --git a/test/core/compile-fail/packed.cpp b/test/core/compile-fail/packed.cpp new file mode 100644 index 00000000..03c24b94 --- /dev/null +++ b/test/core/compile-fail/packed.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2023 Denis Mikhailov +// +// 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) + +#include + +#pragma pack(1) +struct Foo +{ + char ch; + short id; + short opt; + int value; +}; + +int main() { + (void)boost::pfr::get_memptr<3>(boost::pfr::type_identity{}); // Must be a compile time error +} +