C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Specify the mangled name

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 4 Feb 2025 20:54:14 +0000
On Tue, Feb 4, 2025 at 4:02 PM Thiago Macieira wrote:
>
> The easiest of which would be that it includes <fwd/NS/NS/.../name> or <NS/NS/
> name> (whichever exists first) and we just rely on the include system to
> resolve it.


For every class (and every template class) in the standard library,
the Standard could stipulate that there is a corresponding header file
for forward-declaring it, sort of like:

    #include <fwd/std/vector>
    #include <fwd/std/deque>
    #include <fwd/std/list>
    #include <fwd/std/array>
    #include <fwd/std/forward_list>
    #include <fwd/std/set>
    #include <fwd/std/map>
    #include <fwd/std/multiset>
    #include <fwd/std/multimap>
    #include <fwd/std/unordered_set>
    #include <fwd/std/unordered_map>
    #include <fwd/std/unordered_multiset>
    #include <fwd/std/unordered_multimap>
    #include <fwd/std/stack>
    #include <fwd/std/queue>
    #include <fwd/std/priority_queue>
    #include <fwd/std/iterator>
    #include <fwd/std/input_iterator_tag>
    #include <fwd/std/output_iterator_tag>
    #include <fwd/std/forward_iterator_tag>
    #include <fwd/std/bidirectional_iterator_tag>
    #include <fwd/std/random_access_iterator_tag>
    #include <fwd/std/reverse_iterator>
    #include <fwd/std/istream_iterator>
    #include <fwd/std/ostream_iterator>
    #include <fwd/std/back_insert_iterator>
    #include <fwd/std/front_insert_iterator>
    #include <fwd/std/insert_iterator>
    #include <fwd/std/move_iterator>
    #include <fwd/std/istream>
    #include <fwd/std/ostream>
    #include <fwd/std/iostream>
    #include <fwd/std/ifstream>
    #include <fwd/std/ofstream>
    #include <fwd/std/fstream>
    #include <fwd/std/istringstream>
    #include <fwd/std/ostringstream>
    #include <fwd/std/stringstream>
    #include <fwd/std/wistream>
    #include <fwd/std/wostream>
    #include <fwd/std/wiostream>
    #include <fwd/std/wifstream>
    #include <fwd/std/wofstream>
    #include <fwd/std/wfstream>
    #include <fwd/std/pair>
    #include <fwd/std/tuple>
    #include <fwd/std/optional>
    #include <fwd/std/any>
    #include <fwd/std/variant>
    #include <fwd/std/reference_wrapper>
    #include <fwd/std/unique_ptr>
    #include <fwd/std/shared_ptr>
    #include <fwd/std/weak_ptr>
    #include <fwd/std/allocator>
    #include <fwd/std/pmr/polymorphic_allocator>
    #include <fwd/std/default_delete>
    #include <fwd/std/make_shared>
    #include <fwd/std/make_unique>
    #include <fwd/std/thread>
    #include <fwd/std/jthread>
    #include <fwd/std/mutex>
    #include <fwd/std/recursive_mutex>
    #include <fwd/std/timed_mutex>
    #include <fwd/std/recursive_timed_mutex>
    #include <fwd/std/condition_variable>
    #include <fwd/std/condition_variable_any>
    #include <fwd/std/future>
    #include <fwd/std/promise>
    #include <fwd/std/shared_future>
    #include <fwd/std/atomic>
    #include <fwd/std/atomic_flag>
    #include <fwd/std/lock_guard>
    #include <fwd/std/unique_lock>
    #include <fwd/std/exception>
    #include <fwd/std/logic_error>
    #include <fwd/std/runtime_error>
    #include <fwd/std/invalid_argument>
    #include <fwd/std/out_of_range>
    #include <fwd/std/length_error>
    #include <fwd/std/overflow_error>
    #include <fwd/std/underflow_error>
    #include <fwd/std/bad_alloc>
    #include <fwd/std/bad_cast>
    #include <fwd/std/bad_typeid>
    #include <fwd/std/is_integral>
    #include <fwd/std/is_floating_point>
    #include <fwd/std/is_pointer>
    #include <fwd/std/is_reference>
    #include <fwd/std/is_const>
    #include <fwd/std/is_volatile>
    #include <fwd/std/remove_const>
    #include <fwd/std/remove_volatile>
    #include <fwd/std/remove_reference>
    #include <fwd/std/enable_if>
    #include <fwd/std/is_same>
    #include <fwd/std/decay>
    #include <fwd/std/chrono/system_clock>
    #include <fwd/std/chrono/steady_clock>
    #include <fwd/std/chrono/high_resolution_clock>
    #include <fwd/std/chrono/time_point>
    #include <fwd/std/chrono/duration>
    #include <fwd/std/chrono/zoned_time>
    #include <fwd/std/chrono/year_month_day>
    #include <fwd/std/chrono/sys_time>
    #include <fwd/std/complex>
    #include <fwd/std/valarray>
    #include <fwd/std/numeric_limits>
    #include <fwd/std/gcd>
    #include <fwd/std/lcm>
    #include <fwd/std/regex>
    #include <fwd/std/smatch>
    #include <fwd/std/cmatch>
    #include <fwd/std/regex_iterator>
    #include <fwd/std/regex_token_iterator>
    #include <fwd/std/filesystem/path>
    #include <fwd/std/filesystem/directory_entry>
    #include <fwd/std/filesystem/file_status>
    #include <fwd/std/filesystem/directory_iterator>
    #include <fwd/std/filesystem/recursive_directory_iterator>
    #include <fwd/std/net/socket>
    #include <fwd/std/net/tcp_stream>
    #include <fwd/std/net/udp_stream>

Obviously I got ChatGPT to make that list for me, and it tells me that
the total number of classes might be over a thousand.

And as you said, these don't need to be real files. I mean when the
preprocessor encounters the line:

    #include <fwd/std/regex>

It just has to copy-paste:

    namespace std {
        template< class CharT > class regex_traits;
        template< class CharT, class Traits = std::regex_traits<CharT>
> class basic_regex;
        using regex = basic_regex<char>;
    }

Even if there are a thousand classes, and even if each class on
average needs about 150 characters to be forward-declared, then that's
only 150 kilobytes of memory required. A compiler definitely wouldn't
need more than one megabyte of memory to pull this off efficiently.

And an AI like ChatGPT could generate all those
forward-declaration-header-files from the original header files.

Received on 2025-02-04 20:54:20