Skip to content

Commit c4d65ae

Browse files
Add configuration for no_unique_address attribute
1 parent fd2bd0d commit c4d65ae

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ option(
2323
${PROJECT_IS_TOP_LEVEL}
2424
)
2525

26+
# [CPP.NO_FLAG_FORKING]
27+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
28+
set(BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS
29+
"[[msvc::no_unique_address]]"
30+
CACHE STRING
31+
"Name of C++ attribute for empty base optimization of data members"
32+
)
33+
else()
34+
set(BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS
35+
"[[no_unique_address]]"
36+
CACHE STRING
37+
"Name of C++ attribute for empty base optimization of data members"
38+
)
39+
endif()
40+
41+
configure_file(
42+
include/beman/any_view/config.hpp.in
43+
include/beman/any_view/config.hpp
44+
@ONLY
45+
)
46+
2647
set(CMAKE_CXX_EXTENSIONS OFF)
2748

2849
include(FetchContent)
@@ -36,6 +57,7 @@ target_include_directories(
3657
beman.any_view
3758
INTERFACE
3859
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
60+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
3961
$<INSTALL_INTERFACE:include>
4062
)
4163

@@ -51,6 +73,7 @@ install(
5173
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
5274
FILES_MATCHING
5375
PATTERN "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/any_view/*.hpp"
76+
PATTERN "${CMAKE_CURRENT_BINARY_DIR}/include/beman/any_view/*.hpp"
5477
)
5578

5679
macro(beman_add_executable)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
3+
#ifndef BEMAN_ANY_VIEW_CONFIG_HPP
4+
#define BEMAN_ANY_VIEW_CONFIG_HPP
5+
6+
#cmakedefine BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS() @BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS@
7+
8+
#endif // BEMAN_ANY_VIEW_CONFIG_HPP

include/beman/any_view/detail/iterator_adaptor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ template <class ElementT,
1919
std::input_or_output_iterator IteratorT,
2020
std::sentinel_for<IteratorT> SentinelT>
2121
class iterator_adaptor final : public iterator_interface<ElementT, RefT, RValueRefT, DiffT> {
22-
[[no_unique_address]] IteratorT iterator;
23-
[[no_unique_address]] SentinelT sentinel;
22+
BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS() IteratorT iterator;
23+
BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS() SentinelT sentinel;
2424

2525
using iterator_interface = detail::iterator_interface<ElementT, RefT, RValueRefT, DiffT>;
2626
using pointer = std::add_pointer_t<RefT>;

include/beman/any_view/detail/view_adaptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class view_adaptor final : public view_interface<IterConceptT, ElementT, RefT, R
1212
using iterator = detail::any_iterator<IterConceptT, ElementT, RefT, RValueRefT, DiffT>;
1313
using size_type = std::make_unsigned_t<DiffT>;
1414

15-
[[no_unique_address]] ViewT view;
15+
BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS() ViewT view;
1616

1717
static constexpr auto get_noexcept() { return std::is_nothrow_move_constructible_v<ViewT>; }
1818

0 commit comments

Comments
 (0)