Namespaces
Variants
Views
Actions

Talk:cpp/symbol index/macro

From cppreference.com

__cpp_lib_is_implicit_lifetime, __cpp_lib_modules, and __cpp_lib_ranges_enumerate are missing from this page.

Marklmi (talk) 14:56, 4 April 2023 (PDT)

__cpp_lib_int_pow2 is listed out of order compared to other pages. Relative to __cpp_lib_integer_... it is normally listed first. That would look like:

__cpp_lib_int_pow2 (since C++20)

__cpp_lib_integer_comparison_functions (since C++20)

__cpp_lib_integer_sequence (since C++20)

Marklmi (talk) 15:19, 4 April 2023 (PDT)

 Done Yes, thank your. It is all fixed now. Here is a simple script that can help to find the absent FTMs from draft:

[edit] FTM table maintenance scripts

Absent FTM finder script

Can be used online too

// This program finds the Feature Testing Macros absent in cppreference's FTM list.
//
// Usage:
// Fill in the arrays (string_view's) at the end of this file and compile/run this script.
// A compiler options could be: c++ --std=c++20 -O2 ./print_absent_macros.cpp -o o && ./o
// The absent Feature Testing Macros will be sent to stdout.
// 
// Source page1: "http://eel.is/c++draft/libraryindex"
// Source page2: "https://en.cppreference.com/w/cpp/symbol_index/macro"
 
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
 
using VSW = std::vector<std::string_view>;
 
inline void print_differences(VSW&& v1, VSW&& v2)
{
    std::ranges::sort(v1);
    std::ranges::sort(v2);
    std::ranges::set_difference(v1, v2,
        std::ostream_iterator<std::string_view>(std::cout, "\n"));
}
 
inline VSW collect_macros(std::string_view const source)
{
    struct StrPos{
        std::string_view str;
        size_t pos{};
        bool found() const { return not str.empty(); }
    };
 
    auto find_next_macro = [](std::string_view const source, size_t const pos) -> StrPos
    {
        constexpr std::string_view prefix{"__cpp_lib_"};
        auto first = source.find(prefix, pos);
        if (first == source.npos)
            return {};
        auto last = source.find_first_of("},", first + prefix.length() + 1);
        if (last == source.npos)
            return {};
        return { {source.cbegin() + first, last - first}, last + 1 };
    };
 
    VSW macros;
    for (StrPos sp; sp = find_next_macro(source, sp.pos), sp.found();)
        macros.push_back(sp.str);
    return macros;
}
 
int main()
{
    extern const std::string_view ftm_in_draft;
    extern const std::string_view ftm_in_cppreference;
    print_differences(collect_macros(ftm_in_draft), collect_macros(ftm_in_cppreference));
}
 
// Fill from the source: "http://eel.is/c++draft/libraryindex"
//
constexpr std::string_view ftm_in_draft = R"-(
__cpp_lib_adaptor_iterator_pair_constructor, [version.syn]
__cpp_lib_addressof_constexpr, [version.syn]
__cpp_lib_algorithm_iterator_requirements, [version.syn]
__cpp_lib_allocate_at_least, [version.syn]
__cpp_lib_allocator_traits_is_always_equal, [version.syn]
__cpp_lib_any, [version.syn]
__cpp_lib_apply, [version.syn]
__cpp_lib_array_constexpr, [version.syn]
__cpp_lib_as_const, [version.syn]
 
... the rest is not shown ...
)-";
 
// Fill from "https://en.cppreference.com/w/cpp/symbol_index/macro"
//
constexpr std::string_view ftm_in_cppreference = R"-(
{{ltt|cpp/utility/feature_test|__cpp_lib_adaptor_iterator_pair_constructor}}
{{mark since c++23}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_addressof_constexpr}}
{{mark since c++20}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_algorithm_iterator_requirements}}
{{mark since c++23}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_allocate_at_least}}
{{mark since c++23}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_allocator_traits_is_always_equal}}
{{mark since c++20}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_any}}
{{mark since c++20}}<br>
{{ltt|cpp/utility/feature_test|__cpp_lib_apply}}
{{mark since c++20}}<br>
 
... the rest is not shown ...
)-";

Possible output:

__cpp_lib_common_reference
__cpp_lib_common_reference_wrapper
__cpp_lib_formatters
__cpp_lib_is_implicit_lifetime
__cpp_lib_modules
__cpp_lib_ranges_enumerate
__cpp_lib_ranges_find_last
--Space Mission (talk) 09:45, 5 April 2023 (PDT)
--Space Mission (talk) 14:15, 5 April 2023 (PDT)
--Space Mission (talk) 14:46, 6 March 2025 (PST)


FTM sub-table updater script

Can be used online. Compiles few seconds due to regexps.

// This program adds Feature Testing Macros that absent in cppreference's FTM list @
// "https://en.cppreference.com/w/cpp/symbol_index/macro"
//
// Usage:
// Fill in the arrays at the end of this file and compile/run this script.
// The part of Feature Testing Macro table will be sent to stdout. New FTMs are marked
// with "** NEW **" (that should be deleted before insertion into the table).
//
// Source page1: "http://eel.is/c++draft/libraryindex"
// Source page2: "https://en.cppreference.com/w/cpp/symbol_index/macro"
 
#include <array>
#include <iostream>
#include <map>
#include <ranges>
#include <regex>
#include <string>
#include <string_view>
#include <vector>
 
inline std::string_view extract_ftm(std::string_view const source)
{
    static const std::regex re("__cpp_lib_[a-z0-9_]+");
    if (static std::cmatch m; std::regex_search(source.data(), m, re))
        return std::string_view(source.data() + m.position(), m.length());
    return {};
}
 
int main()
{
    extern const std::string_view ftm_in_draft;
    extern const std::string_view ftm_in_cppreference;
 
    std::vector<std::string_view> draft;
    for (draft.reserve(512); auto line : ftm_in_draft | std::views::split('\n'))
        if (auto t{extract_ftm(std::string_view(line))}; not t.empty())
            draft.emplace_back(t);
 
    std::map<std::string_view, std::string> cppref;
    for (auto line : ftm_in_cppreference | std::views::split('\n'))
        if (std::string_view s{line}, t{extract_ftm(s)}; not t.empty())
            cppref[t] = s;
 
    for (const auto s : draft)
        if (not cppref.contains(s))
            cppref[s] = "{{ftml|" + std::string(s) + "|C++26}}<br> ** NEW **";
 
    for (const auto& [_, entry] : cppref)
        std::cout << entry << '\n';
}
 
// Fill from the source: "http://eel.is/c++draft/libraryindex"
//
constexpr std::string_view ftm_in_draft = R"-(
__cpp_lib_adaptor_iterator_pair_constructor, [version.syn]
__cpp_lib_addressof_constexpr, [version.syn]
__cpp_lib_algorithm_default_value_type, [version.syn]
__cpp_lib_algorithm_iterator_requirements, [version.syn]
__cpp_lib_aligned_accessor, [version.syn]
__cpp_lib_allocate_at_least, [version.syn]
__cpp_lib_allocator_traits_is_always_equal, [version.syn]
__cpp_lib_any, [version.syn]
... the rest is skipped ...
)-";
 
// Fill from "https://en.cppreference.com/w/cpp/symbol_index/macro"
//
constexpr std::string_view ftm_in_cppreference = R"-(
{{ftml|__cpp_lib_adaptor_iterator_pair_constructor|C++23}}<br>
{{ftml|__cpp_lib_addressof_constexpr|C++17}}<br>
{{ftml|__cpp_lib_algorithm_default_value_type|C++26}}<br>
{{ftml|__cpp_lib_algorithm_iterator_requirements|C++23}}<br>
{{ftml|__cpp_lib_allocate_at_least|C++23}}<br>
{{ftml|__cpp_lib_allocator_traits_is_always_equal|C++17}}<br>
{{ftml|__cpp_lib_any|C++17}}<br>
... the rest is skipped ...
)-";

--Space Mission (talk) 14:46, 6 March 2025 (PST)