# Feature-test Macros

## Description

oneTBB defines a set of preprocessor macros corresponding to the features provided by the library. They are intended for detecting the presence of these features.

Each of these macros is defined in the header `<oneapi/tbb/version.h>` and in the feature headers specified in the table below.

For preview features, the feature test macro is only defined if the feature is enabled by defining its preview macro. You cannot use a feature test macro to guard setting of the feature preview macro. For example:

    // Wrong
    #include <oneapi/tbb/version.h>
    #if TBB_HAS_FEATURE_X
    #define TBB_PREVIEW_FEATURE_X 1 // Never reached
    #include <oneapi/tbb/feature_header.h>
    #endif
    // Correct
    #define TBB_PREVIEW_FEATURE_X 1
    #include <oneapi/tbb/version.h>
    #if TBB_HAS_FEATURE_X
    #include <oneapi/tbb/feature_header.h>
    #endif

Each macro value follows the pattern `YYYYMM`, where `YYYY` is a year, and `MM` is a month when the corresponding feature was introduced or updated. These values can be increased if the capabilities of given features are extended. The table below contains only the most recent values.

Feature | Macro Name | Value | Header(s)
--- | --- | --- | ---
Resource Limiting in the Flow Graph | `TBB_HAS_FLOW_GRAPH_RESOURCE_LIMITING` | `202603` | `<oneapi/tbb/flow_graph.h>`
parallel_phase Interface for Task Arena | `TBB_HAS_PARALLEL_PHASE` | `202603` | `<oneapi/tbb/task_arena.h>`
Core Type Selector for Task Arena Constraints | `TBB_HAS_TASK_ARENA_CORE_TYPE_SELECTOR` | `202603` | `<oneapi/tbb/task_arena.h>` `<oneapi/tbb/info.h>`
task_group Dynamic Dependencies | `TBB_HAS_TASK_GROUP_DEPENDENCIES` | `202603` | `<oneapi/tbb/task_group.h>` `<oneapi/tbb/task_arena.h>`
Waiting for Individual Tasks in task_group | `TBB_HAS_TASK_GROUP_WAIT_FOR_SINGLE_TASK` | `202603` | `<oneapi/tbb/task_group.h>` `<oneapi/tbb/task_arena.h>`
Allocate Memory Interleaved between NUMA Nodes | `TBB_HAS_NUMA_ALLOCATION` | `202605` | `<oneapi/tbb/numa_allocation.h>`

### Example

The following example uses a feature-test macro to conditionally enable `parallel_phase` hints when supported by the library:

    #define TBB_PREVIEW_PARALLEL_PHASE 1

    #include <oneapi/tbb/version.h>
    #include <oneapi/tbb/parallel_for.h>

    #if TBB_HAS_PARALLEL_PHASE
    #include <oneapi/tbb/task_arena.h>
    #endif

    int main() {
    #if TBB_HAS_PARALLEL_PHASE
        tbb::this_task_arena::start_parallel_phase();
    #endif

        tbb::parallel_for(parallel_loop1_begin, parallel_loop1_end,
                          parallel_loop1_body{});

        tbb::parallel_for(parallel_loop2_begin, parallel_loop2_end,
                          parallel_loop2_body{});

    #if TBB_HAS_PARALLEL_PHASE
        tbb::this_task_arena::end_parallel_phase(/*with_fast_leave=*/true);
    #endif
    }