C ++ 20が近づいています。 ジャクソンビル会議

3月上旬に、標準化C ++に関する国際ワーキンググループWG21の会議がアメリカのジャクソンビル市で終了しました。 会議では、新しいコンポーネントの「プレビュー」のリリースに備えて、C ++ 20でチップを追加し、舌の粗さの輝きに磨きました。

ニュースを見て、調べたい:


カレンダーとタイムゾーン


C ++ 20で日付がいかに美しく簡単に設定できるかをご覧ください。

using std::chrono;
year_month_day ymd = 2016y/May/29d; // 2016-05-29

, ? :

auto tp = sys_days{ymd} + 7h + 30min + 6s + 153ms; // 2016-05-29 07:30:06.153 UTC
zoned_time zt = {"Asia/Tokyo", tp};
cout << zt << '\n';                                          // 2016-05-29 16:30:06.153 JST

, , « », « » « ». ..

4000 :

auto last_friday_feb = February/Friday[last];
std::cout << 4000 / last_friday_feb << std::endl;

.

Span


std::string_view C++17 ( boost::string_view/boost::string_ref), std::span !

, , - int:

void do_something(int* p, size_t size);

:

std::vector<int> v;
do_something(v.data(), v.size());

int data[1024];
do_something(data, std::size(data));

boost::container::small_vector<int, 32> sm;
do_something(sm.data(), sm.size());

— + range based for:

void do_something(int* p, size_t size) {
    std::sort(p, p + size);
    for (size_t i = 0; i < size; ++i) {
        p[i] += p[0];
    }
}

, std::span — , ( , , ). :

void do_something(std::span<int> p) {
    std2::sort(p);
    for (int& v: p) {
        v += p[0];
    }
}
// ...
std::vector<int> v;
do_something(v);

int data[1024];
do_something(data);

boost::container::small_vector<int, 32> sm;
do_something(sm);

std::span pdf.

typename? C++20!


, typename, – , ! C++20 typename:


template<class T> T::R f();

template<class T> struct S {
    using Ptr = PtrTraits<T>::Ptr;

    T::R f(T::P p) {
        return static_cast<T::R>(p);
    }

    auto g() -> S<T*>::Ptr;
};




onstexpr


– std::allocator constexpr . , – C++20 std::vector std::string, . , , .

, . , , 21 «constexpr iterator», , . constexpr .

, , , Herb Sutter “Meta: Thoughts on generative C++”.


«Parallelism 2 TS». , , SIMD , . (SSE, AVX, NEON, MDMX ..):

void compute_on_aligned_data(float* data, size_t N) {
    size_t i = 0;
    for (; i + native_simd<float>::size() <= N; i += native_simd<float>::size()) {
        native_simd<float> v(data + i, vector_aligned);
        where(v > 100.f, v) = 100.f + (v - 100.f) * 0.1f;
        v.copy_to(data + i, vector_aligned);
    }

    for (; i < N; ++i) {
        float x = data[i];
        if (x > 100.f) {
            x = 100.f + (x - 100.f) * 0.1f;
        }
        data[i] = x;
    }
}

SIMD .

( fork based , , ..) .


.


, promise. , . , , :

future​<std::string>​ ​concat​(const​ std::string​& ​ prefix​, future​<std::string>​ suffix​) {
    co_return ​ (prefix ​ + ​ co_await suffix​);
}


, . . , .

Reflection TS


TS . . .


, C++, .

C++. , WG21, .

. C++ . Houdini, , C++ C++11.


. - C++ , https://stdcpp.ru/, 21 .

? C++ Russia .

C++ ? , memory_order_relaxed memory_order_seq_cst.

, C++20 .


Source: https://habr.com/ru/post/J351492/


All Articles