C++ C++;宏将文本替换为零

C++ C++;宏将文本替换为零,c++,macros,C++,Macros,宏通常用于文本替换。在我的例子中,我需要有条件地删除一些关键字,以便在没有特定功能的编译器中进行编译 具体来说,我一直在研究这段代码的来源 template <typename C> struct has_size { template <typename T> static constexpr auto check(T*) -> // problem in VS2013 typename std::is_integral<

宏通常用于文本替换。在我的例子中,我需要有条件地删除一些关键字,以便在没有特定功能的编译器中进行编译

具体来说,我一直在研究这段代码的来源

template <typename C>
struct has_size {
    template <typename T>
    static constexpr auto check(T*) -> // problem in VS2013
        typename std::is_integral<
            decltype(std::declval<T const>().size())>::type;
// .. some more stuff
};
因此,在gcc编译中,它将被
constexpr
替换,而在VS编译中,它将被文本上的nothing替换

当然,简单地说:

#define constexpr
constexpr
展开为空。您可以将此宏定义封装在不支持此定义的编译器的适当
#if

有时,人们会使“空”扩展更加明确:

#define constexpr /* nothing */
当然,简单地说:

#define constexpr
constexpr
展开为空。您可以将此宏定义封装在不支持此定义的编译器的适当
#if

有时,人们会使“空”扩展更加明确:

#define constexpr /* nothing */

简单地
#define constepr
简单地
#define constepr
我在include-guards中看到过很多次,不知怎的,我推断它只定义了一个用于检查
#ifndef
#ifdef
的符号。感谢您的快速响应我在include guards中多次看到这一点,因此我推断它只定义了一个符号,用于使用
\ifndef
\ifdef
进行检查。谢谢你的快速回复