forked from boostorg/config
Move BOOST_STRINGIZE, BOOST_JOIN to config/helper_macros.hpp; use BOOST_STRINGIZE in BOOST_PRAGMA_MESSAGE
This commit is contained in:
@@ -537,25 +537,10 @@ namespace std{ using ::type_info; }
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------//
|
||||||
|
|
||||||
//
|
|
||||||
// Helper macro BOOST_STRINGIZE:
|
// Helper macro BOOST_STRINGIZE:
|
||||||
// Converts the parameter X to a string after macro replacement
|
|
||||||
// on X has been performed.
|
|
||||||
//
|
|
||||||
#define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X)
|
|
||||||
#define BOOST_DO_STRINGIZE(X) #X
|
|
||||||
|
|
||||||
//
|
|
||||||
// Helper macro BOOST_JOIN:
|
// Helper macro BOOST_JOIN:
|
||||||
// The following piece of macro magic joins the two
|
|
||||||
// arguments together, even when one of the arguments is
|
#include <boost/config/helper_macros.hpp>
|
||||||
// itself a macro (see 16.3.1 in C++ standard). The key
|
|
||||||
// is that macro expansion of macro arguments does not
|
|
||||||
// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN.
|
|
||||||
//
|
|
||||||
#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
|
|
||||||
#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
|
|
||||||
#define BOOST_DO_JOIN2( X, Y ) X##Y
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set some default values for compiler/library/platform names.
|
// Set some default values for compiler/library/platform names.
|
||||||
|
37
include/boost/config/helper_macros.hpp
Normal file
37
include/boost/config/helper_macros.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED
|
||||||
|
#define BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED
|
||||||
|
|
||||||
|
// Copyright 2001 John Maddock.
|
||||||
|
// Copyright 2017 Peter Dimov.
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// BOOST_STRINGIZE(X)
|
||||||
|
// BOOST_JOIN(X, Y)
|
||||||
|
//
|
||||||
|
// Note that this header is C compatible.
|
||||||
|
|
||||||
|
//
|
||||||
|
// Helper macro BOOST_STRINGIZE:
|
||||||
|
// Converts the parameter X to a string after macro replacement
|
||||||
|
// on X has been performed.
|
||||||
|
//
|
||||||
|
#define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X)
|
||||||
|
#define BOOST_DO_STRINGIZE(X) #X
|
||||||
|
|
||||||
|
//
|
||||||
|
// Helper macro BOOST_JOIN:
|
||||||
|
// The following piece of macro magic joins the two
|
||||||
|
// arguments together, even when one of the arguments is
|
||||||
|
// itself a macro (see 16.3.1 in C++ standard). The key
|
||||||
|
// is that macro expansion of macro arguments does not
|
||||||
|
// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN.
|
||||||
|
//
|
||||||
|
#define BOOST_JOIN(X, Y) BOOST_DO_JOIN(X, Y)
|
||||||
|
#define BOOST_DO_JOIN(X, Y) BOOST_DO_JOIN2(X,Y)
|
||||||
|
#define BOOST_DO_JOIN2(X, Y) X##Y
|
||||||
|
|
||||||
|
#endif // BOOST_CONFIG_HELPER_MACROS_HPP_INCLUDED
|
@@ -9,14 +9,17 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
//
|
//
|
||||||
// BOOST_PRAGMA_MESSAGE("message")
|
// BOOST_PRAGMA_MESSAGE("message")
|
||||||
|
//
|
||||||
|
// Expands to the equivalent of #pragma message("message")
|
||||||
|
//
|
||||||
|
// Note that this header is C compatible.
|
||||||
|
|
||||||
|
#include <boost/config/helper_macros.hpp>
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define BOOST_PRAGMA_MESSAGE_IMPL_1(x) _Pragma(#x)
|
#define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
|
||||||
#define BOOST_PRAGMA_MESSAGE(x) BOOST_PRAGMA_MESSAGE_IMPL_1(message(x))
|
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define BOOST_PRAGMA_MESSAGE_IMPL_2(x, f, ln) __pragma(message(f "(" #ln "): note: " x))
|
#define BOOST_PRAGMA_MESSAGE(x) __pragma(message(__FILE__ "(" BOOST_STRINGIZE(__LINE__) "): note: " x))
|
||||||
#define BOOST_PRAGMA_MESSAGE_IMPL_1(x, f, ln) BOOST_PRAGMA_MESSAGE_IMPL_2(x, f, ln)
|
|
||||||
#define BOOST_PRAGMA_MESSAGE(x) BOOST_PRAGMA_MESSAGE_IMPL_1(x, __FILE__, __LINE__)
|
|
||||||
#else
|
#else
|
||||||
#define BOOST_PRAGMA_MESSAGE(x)
|
#define BOOST_PRAGMA_MESSAGE(x)
|
||||||
#endif
|
#endif
|
||||||
|
@@ -103,6 +103,7 @@ test-suite config
|
|||||||
[ run cstdint_test2.cpp : : : <warnings>all <toolset>gcc:<cxxflags>"-Wno-long-long -Wextra" <toolset>darwin:<cxxflags>-Wno-long-long ]
|
[ run cstdint_test2.cpp : : : <warnings>all <toolset>gcc:<cxxflags>"-Wno-long-long -Wextra" <toolset>darwin:<cxxflags>-Wno-long-long ]
|
||||||
[ compile cstdint_include_test.cpp : <warnings>all <toolset>gcc:<cxxflags>-Wextra ]
|
[ compile cstdint_include_test.cpp : <warnings>all <toolset>gcc:<cxxflags>-Wextra ]
|
||||||
[ run config_build_check.cpp : : : [ requires int128 cxx11_constexpr cxx11_user_defined_literals ] ]
|
[ run config_build_check.cpp : : : [ requires int128 cxx11_constexpr cxx11_user_defined_literals ] ]
|
||||||
|
[ run helper_macros_test.cpp ]
|
||||||
[ compile pragma_message_test.cpp ]
|
[ compile pragma_message_test.cpp ]
|
||||||
;
|
;
|
||||||
|
|
||||||
|
30
test/helper_macros_test.cpp
Normal file
30
test/helper_macros_test.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright 2017 Peter Dimov.
|
||||||
|
//
|
||||||
|
// 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 <boost/config/helper_macros.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#define X pumpkin
|
||||||
|
|
||||||
|
BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(X), "pumpkin" );
|
||||||
|
BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(__LINE__), "16" );
|
||||||
|
|
||||||
|
#define Y 2
|
||||||
|
|
||||||
|
int BOOST_JOIN(X, Y) = 0;
|
||||||
|
(void)pumpkin2;
|
||||||
|
|
||||||
|
int BOOST_JOIN(X, __LINE__) = 0;
|
||||||
|
(void)pumpkin23;
|
||||||
|
|
||||||
|
BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(BOOST_JOIN(X, Y)), "pumpkin2" );
|
||||||
|
BOOST_TEST_CSTR_EQ( BOOST_STRINGIZE(BOOST_JOIN(X, __LINE__)), "pumpkin27" );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user