최대 1 분 소요

개요

  • reference
  • C++11 이상에 도입된 C++ 언어 및 라이브러리 기능에 해당하는 일련의 전처리기 매크로를 정의
  • attributes
    • __has_cpp_attribute( attribute-token )
    • attribute에 대한 컴파일러 지원 여부 확인 등에 사용
  • language features
    • 기능에 대한 매크로
    • 년/월에 대한 정수 리터럴로 확장
    • 기능 목록은 reference 확인
  • library features
    • 라이브러리에 대한 매크로
    • 년/월에 대한 정수 리터럴로 확장
    • 라이브러리 목록은 reference 확인


예제

  • 코드
    #include <iostream>

    using namespace std;

    void attributes() {
    #if __has_cpp_attribute(assume)
    	cout << "support assume" << endl;
    #endif

    #if __has_cpp_attribute(deprecated)
    	cout << "support deprecated" << endl;
    #endif

    #if __has_cpp_attribute(maybe_unused)
    	cout << "support maybe_unused" << endl;
    #endif
    }

    void language_features() {
    #if defined(__cpp_concepts)
    	cout << __cpp_concepts << endl;
    #endif

    #if defined(__cpp_lambdas)
    	cout << __cpp_lambdas << endl;
    #endif
    }

    void library_features() {
    #if defined(__cpp_lib_concepts)
    	cout << __cpp_lib_concepts << endl;
    #endif

    #if defined(__cpp_lib_string_view)
    	cout << __cpp_lib_string_view << endl;
    #endif
    }

    int main() {
    	attributes();

    	cout << "------" << endl;

    	language_features();

    	cout << "------" << endl;

    	library_features();

    	return 0;
    }
  • 실행 결과
    support deprecated
    support maybe_unused
    ------
    202002
    200907
    ------
    202002
    201803