Skip to content

Commit

Permalink
Mark constexpr global variables as inline.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Aug 6, 2024
1 parent 30227a3 commit efdc25a
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion asio/include/asio/as_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct partial_as_tuple
* asynchronous operation's default completion token (or asio::deferred
* if no default is available).
*/
constexpr partial_as_tuple as_tuple;
ASIO_INLINE_VARIABLE constexpr partial_as_tuple as_tuple;

} // namespace asio

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/deferred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ inline auto operator|(Head head, Tail&& tail)
/**
* See the documentation for asio::deferred_t for a usage example.
*/
constexpr deferred_t deferred;
ASIO_INLINE_VARIABLE constexpr deferred_t deferred;

} // namespace asio

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/detached.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class detached_t
/**
* See the documentation for asio::detached_t for a usage example.
*/
constexpr detached_t detached;
ASIO_INLINE_VARIABLE constexpr detached_t detached;

} // namespace asio

Expand Down
13 changes: 13 additions & 0 deletions asio/include/asio/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@
# endif // !defined(ASIO_DISABLE_VARIADIC_LAMBDA_CAPTURES)
#endif // !defined(ASIO_HAS_VARIADIC_LAMBDA_CAPTURES)

// Support for inline variables.
#if !defined(ASIO_HAS_INLINE_VARIABLES)
# if !defined(ASIO_DISABLE_INLINE_VARIABLES)
# if (__cplusplus >= 201703) && (__cpp_inline_variables >= 201606)
# define ASIO_HAS_INLINE_VARIABLES 1
# define ASIO_INLINE_VARIABLE inline
# endif // (__cplusplus >= 201703) && (__cpp_inline_variables >= 201606)
# endif // !defined(ASIO_DISABLE_INLINE_VARIABLES)
#endif // !defined(ASIO_HAS_INLINE_VARIABLES)
#if !defined(ASIO_INLINE_VARIABLE)
# define ASIO_INLINE_VARIABLE
#endif // !defined(ASIO_INLINE_VARIABLE)

// Default alignment.
#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
# define ASIO_DEFAULT_ALIGN __STDCPP_DEFAULT_NEW_ALIGNMENT__
Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const T allocator_t<void>::static_query_v;
#endif // defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
// && defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)

constexpr allocator_t<void> allocator;
ASIO_INLINE_VARIABLE constexpr allocator_t<void> allocator;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/blocking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ const T never_t<I>::static_query_v;

typedef detail::blocking_t<> blocking_t;

constexpr blocking_t blocking;
ASIO_INLINE_VARIABLE constexpr blocking_t blocking;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/blocking_adaptation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ void blocking_execute(

typedef detail::blocking_adaptation_t<> blocking_adaptation_t;

constexpr blocking_adaptation_t blocking_adaptation;
ASIO_INLINE_VARIABLE constexpr blocking_adaptation_t blocking_adaptation;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const T context_t<I>::static_query_v;

typedef detail::context_t<> context_t;

constexpr context_t context;
ASIO_INLINE_VARIABLE constexpr context_t context;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/mapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ const T other_t<I>::static_query_v;

typedef detail::mapping_t<> mapping_t;

constexpr mapping_t mapping;
ASIO_INLINE_VARIABLE constexpr mapping_t mapping;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/occupancy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const T occupancy_t<I>::static_query_v;

typedef detail::occupancy_t<> occupancy_t;

constexpr occupancy_t occupancy;
ASIO_INLINE_VARIABLE constexpr occupancy_t occupancy;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/outstanding_work.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ const T tracked_t<I>::static_query_v;

typedef detail::outstanding_work_t<> outstanding_work_t;

constexpr outstanding_work_t outstanding_work;
ASIO_INLINE_VARIABLE constexpr outstanding_work_t outstanding_work;

} // namespace execution

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/execution/relationship.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ const T continuation_t<I>::static_query_v;

typedef detail::relationship_t<> relationship_t;

constexpr relationship_t relationship;
ASIO_INLINE_VARIABLE constexpr relationship_t relationship;

} // namespace execution

Expand Down
4 changes: 2 additions & 2 deletions asio/include/asio/experimental/use_coro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ struct use_coro_t
* See the documentation for asio::use_coro_t for a usage example.
*/
#if defined(GENERATING_DOCUMENTATION)
constexpr use_coro_t<> use_coro;
ASIO_INLINE_VARIABLE constexpr use_coro_t<> use_coro;
#else
constexpr use_coro_t<> use_coro(0, 0, 0);
ASIO_INLINE_VARIABLE constexpr use_coro_t<> use_coro(0, 0, 0);
#endif

} // namespace experimental
Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/experimental/use_promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct use_promise_t
Allocator allocator_;
};

constexpr use_promise_t<> use_promise;
ASIO_INLINE_VARIABLE constexpr use_promise_t<> use_promise;

} // namespace experimental
} // namespace asio
Expand Down
18 changes: 12 additions & 6 deletions asio/include/asio/placeholders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ unspecified signal_number;

#else

static constexpr auto& error = std::placeholders::_1;
static constexpr auto& bytes_transferred = std::placeholders::_2;
static constexpr auto& iterator = std::placeholders::_2;
static constexpr auto& results = std::placeholders::_2;
static constexpr auto& endpoint = std::placeholders::_2;
static constexpr auto& signal_number = std::placeholders::_2;
static ASIO_INLINE_VARIABLE constexpr auto& error
= std::placeholders::_1;
static ASIO_INLINE_VARIABLE constexpr auto& bytes_transferred
= std::placeholders::_2;
static ASIO_INLINE_VARIABLE constexpr auto& iterator
= std::placeholders::_2;
static ASIO_INLINE_VARIABLE constexpr auto& results
= std::placeholders::_2;
static ASIO_INLINE_VARIABLE constexpr auto& endpoint
= std::placeholders::_2;
static ASIO_INLINE_VARIABLE constexpr auto& signal_number
= std::placeholders::_2;

#endif

Expand Down
4 changes: 2 additions & 2 deletions asio/include/asio/this_coro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct executor_t
};

/// Awaitable object that returns the executor of the current coroutine.
constexpr executor_t executor;
ASIO_INLINE_VARIABLE constexpr executor_t executor;

/// Awaitable type that returns the cancellation state of the current coroutine.
struct cancellation_state_t
Expand All @@ -57,7 +57,7 @@ struct cancellation_state_t
* // ...
* } @endcode
*/
constexpr cancellation_state_t cancellation_state;
ASIO_INLINE_VARIABLE constexpr cancellation_state_t cancellation_state;

#if defined(GENERATING_DOCUMENTATION)

Expand Down
4 changes: 2 additions & 2 deletions asio/include/asio/use_awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ struct use_awaitable_t
* See the documentation for asio::use_awaitable_t for a usage example.
*/
#if defined(GENERATING_DOCUMENTATION)
constexpr use_awaitable_t<> use_awaitable;
ASIO_INLINE_VARIABLE constexpr use_awaitable_t<> use_awaitable;
#else
constexpr use_awaitable_t<> use_awaitable(0, 0, 0);
ASIO_INLINE_VARIABLE constexpr use_awaitable_t<> use_awaitable(0, 0, 0);
#endif

} // namespace asio
Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/use_future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class use_future_t
/**
* See the documentation for asio::use_future_t for a usage example.
*/
constexpr use_future_t<> use_future;
ASIO_INLINE_VARIABLE constexpr use_future_t<> use_future;

} // namespace asio

Expand Down
2 changes: 1 addition & 1 deletion asio/include/asio/uses_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct executor_arg_t
* See asio::executor_arg_t and asio::uses_executor
* for more information.
*/
constexpr executor_arg_t executor_arg;
ASIO_INLINE_VARIABLE constexpr executor_arg_t executor_arg;

/// The uses_executor trait detects whether a type T has an associated executor
/// that is convertible from type Executor.
Expand Down
1 change: 1 addition & 0 deletions asio/src/doc/reference.dox
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ PREDEFINED = GENERATING_DOCUMENTATION \
ASIO_CONSTEXPR=constexpr \
ASIO_NOEXCEPT=noexcept \
ASIO_NODISCARD= \
ASIO_INLINE_VARIABLE= \
ASIO_COMPLETION_SIGNATURE=typename \
ASIO_COMPLETION_HANDLER_FOR(s)=typename \
ASIO_COMPLETION_TOKEN_FOR(s)=typename \
Expand Down

0 comments on commit efdc25a

Please sign in to comment.