C ++ 17의 새로운 기능은 무엇입니까?
C ++ 17은 이제 기능이 완전하므로 큰 변화가 없을 것입니다. C ++ 17에 대한 수백 개의 제안이 제출되었습니다.
C ++ 17에서 C ++에 추가 된 기능은 무엇입니까?
"C ++ 1z"를 지원하는 C ++ 컴파일러를 사용할 때 컴파일러가 C ++ 17로 업데이트 할 때 사용할 수있는 기능은 무엇입니까?
언어 기능 :
템플릿 및 일반 코드
-
- 함수가 템플릿 인수를 추론하는 방식과 마찬가지로 이제 생성자는 클래스의 템플릿 인수를 추론 할 수 있습니다.
- http://wg21.link/p0433r2 http://wg21.link/p0620r0 http://wg21.link/p0512r0
-
- 모든 (유형이 아닌 템플릿 인수) 유형의 값을 나타냅니다.
람다
-
- Lambda는 자격이있는 경우 암시 적으로 constexpr입니다.
-
[*this]{ std::cout << could << " be " << useful << '\n'; }
속성
이제 컴파일러는 인식하지 못하는 비표준 속성을 무시해야합니다 .
- C ++ 14 문구는 컴파일러가 알 수없는 범위 속성을 거부하도록 허용했습니다.
구문 정리
-
- 인라인 함수처럼
- 컴파일러는 인스턴스가 인스턴스화되는 위치를 선택합니다.
- 이제 암시 적으로 인라인 된 정적 constexpr redeclaration을 사용하지 않습니다 .
static_assert(expression);문자열이없는 단순전혀
throw하지 않는 한throw(), 그리고throw()이다noexcept(true).
더 깨끗한 다중 리턴 및 흐름 제어
-
- 기본적으로, 일류
std::tie와auto - 예:
const auto [it, inserted] = map.insert( {"foo", bar} );- 변수 작성
it및inserted으로부터 유추 유형을pair이map::insert돌아갑니다.
- tuple / pair-likes &
std::arrays 및 상대적으로 평평한 구조체 와 함께 작동 합니다. - 표준에서 실제로 명명 된 구조화 된 바인딩
- 기본적으로, 일류
if (init; condition)과switch (init; condition)if (const auto [it, inserted] = map.insert( {"foo", bar} ); inserted)- 현명하게 bool로 변환 할 수없는
if(decl)경우로 확장합니다decl.
-
- 주로 센티널 또는 시작 반복기와 동일한 유형이 아닌 종료 반복기를 지원하는 것으로 보이며, 이는 널 종료 루프 등에 도움이됩니다.
-
- 거의 일반적인 코드를 단순화하기 위해 많이 요청 된 기능입니다.
기타
-
- 드디어!
- 모든 경우에 해당되는 것은 아니지만 제거라고하는 "무언가 생성"하는 구문을 "정품 제거"와 구별합니다.
(일부) 표현식에 대한 평가 순서를 수정 하여 수정했습니다.
- 함수 인수를 포함하지 않지만 함수 인수 평가 인터리빙이 이제 금지됨
- 대부분의 깨진 코드가 작동하도록 만들고
.then향후 작업을 수행합니다.
전방 진행 보장 (FPG) (또한 병렬 알고리즘 용 FPG )
- 나는 이것이 "구현이 스레드를 영원히 멈출 수 없다"고 말하는 것이라고 생각한다.
u8'U', u8'T', u8'F', u8'8'문자 리터럴 (이미 존재하는 문자열)-
- 헤더 파일 포함이 오류인지 테스트
- 실험에서 표준으로 거의 원활하게 마이그레이션
라이브러리 추가 :
데이터 유형
-
- 마지막으로 확인한 거의 항상 비어 있지 않습니까?
- 태그가 지정된 유니온 유형
- {굉장한 | 유용한}
-
- 어쩌면 뭔가를 들고
- 엄청나게 유용함
-
- (복사 가능) 무엇이든 보유
-
std::string참조-문자 배열 또는 하위 문자열과 같은- 다시는받지 마십시오
string const&. 또한 파싱을 bajillion 배 더 빠르게 만들 수 있습니다. "hello world"sv- constexpr
char_traits
std::byte씹을 수있는 것보다 더 많이 꺼냅니다.- 정수도 문자도 아닌 데이터 만
물건 호출
std::invoke- 하나의 구문으로 모든 호출 가능 (함수 포인터, 함수, 멤버 포인터)을 호출합니다. 표준 INVOKE 개념에서.
std::apply- Takes a function-like and a tuple, and unpacks the tuple into the call.
std::make_from_tuple,std::applyapplied to object constructionis_invocable,is_invocable_r,invoke_result- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0077r2.html
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0604r0.html
- Deprecates
result_of is_invocable<Foo(Args...), R>is "can you callFoowithArgs...and get something compatible withR", whereR=voidis default.invoke_result<Foo, Args...>isstd::result_of_t<Foo(Args...)>but apparently less confusing?
File System TS v1
[class.directory_iterator]and[class.recursive_directory_iterator]fstreams can be opened withpaths, as well as withconst path::value_type*strings.
New algorithms
for_each_nreducetransform_reduceexclusive_scaninclusive_scantransform_exclusive_scantransform_inclusive_scanAdded for threading purposes, exposed even if you aren't using them threaded
Threading
-
- Untimed, which can be more efficient if you don't need it.
atomic<T>::is_always_lockfree-
- Saves some
std::lockpain when locking more than one mutex at a time.
- Saves some
-
- The linked paper from 2014, may be out of date
- Parallel versions of
stdalgorithms, and related machinery
(parts of) Library Fundamentals TS v1 not covered above or below
[func.searchers]and[alg.search]- A searching algorithm and techniques
-
- Polymorphic allocator, like
std::functionfor allocators - And some standard memory resources to go with it.
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0358r1.html
- Polymorphic allocator, like
std::sample, sampling from a range?
Container Improvements
try_emplaceandinsert_or_assign- gives better guarantees in some cases where spurious move/copy would be bad
Splicing for
map<>,unordered_map<>,set<>, andunordered_set<>- Move nodes between containers cheaply.
- Merge whole containers cheaply.
non-const
.data()for string.non-member
std::size,std::empty,std::data- like
std::begin/end
- like
The
emplacefamily of functions now returns a reference to the created object.
Smart pointer changes
unique_ptr<T[]>fixes and otherunique_ptrtweaks.weak_from_thisand some fixed to shared from this
Other std datatype improvements:
{}construction ofstd::tupleand other improvements- TriviallyCopyable reference_wrapper, can be performance boost
Misc
C++17 library is based on C11 instead of C99
Reserved
std[0-9]+for future standard libraries-
- utility code already in most
stdimplementations exposed
- utility code already in most
- Special math functions
- scientists may like them
std::clamp()std::clamp( a, b, c ) == std::max( b, std::min( a, c ) )roughly
gcdandlcmstd::uncaught_exceptions- Required if you want to only throw if safe from destructors
std::as_conststd::bool_constant- A whole bunch of
_vtemplate variables std::void_t<T>- Surprisingly useful when writing templates
std::owner_less<void>- like
std::less<void>, but for smart pointers to sort based on contents
- like
std::chronopolishstd::conjunction,std::disjunction,std::negationexposedstd::not_fn- Rules for noexcept within
std - std::is_contiguous_layout, useful for efficient hashing
- std::to_chars/std::from_chars, high performance, locale agnostic number conversion; finally a way to serialize/deserialize to human readable formats (JSON & co)
std::default_order, indirection over(breaks ABI of some compilers due to name mangling, removed.)std::less.
Traits
Deprecated
- Some C libraries,
<codecvt>memory_order_consumeresult_of, replaced withinvoke_resultshared_ptr::unique, it isn't very threadsafe
Isocpp.org has has an independent list of changes since C++14; it has been partly pillaged.
Naturally TS work continues in parallel, so there are some TS that are not-quite-ripe that will have to wait for the next iteration. The target for the next iteration is C++20 as previously planned, not C++19 as some rumors implied. C++1O has been avoided.
Initial list taken from this reddit post and this reddit post, with links added via googling or from the above isocpp.org page.
Additional entries pillaged from SD-6 feature-test list.
clang's feature list and library feature list are next to be pillaged. This doesn't seem to be reliable, as it is C++1z, not C++17.
these slides had some features missing elsewhere.
While "what was removed" was not asked, here is a short list of a few things ((mostly?) previous deprecated) that are removed in C++17 from C++:
Removed:
register, keyword reserved for future usebool b; ++b;- trigraphs
- if you still need them, they are now part of your source file encoding, not part of language
- ios aliases
- auto_ptr, old
<functional>stuff,random_shuffle - allocators in
std::function
There were rewordings. I am unsure if these have any impact on code, or if they are just cleanups in the standard:
Papers not yet integrated into above:
P0505R0 (constexpr chrono)
P0418R2 (atomic tweaks)
P0512R0 (template argument deduction tweaks)
P0490R0 (structured binding tweaks)
P0513R0 (changes to
std::hash)P0502R0 (parallel exceptions)
P0509R1 (updating restrictions on exception handling)
P0012R1 (make exception specifications be part of the type system)
P0510R0 (restrictions on variants)
P0504R0 (tags for optional/variant/any)
P0497R0 (shared ptr tweaks)
P0508R0 (structured bindings node handles)
P0521R0 (shared pointer use count and unique changes?)
Spec changes:
Further reference:
https://isocpp.org/files/papers/p0636r0.html
- Should be updated to "Modifications to existing features" here.
참고URL : https://stackoverflow.com/questions/38060436/what-are-the-new-features-in-c17
'Development Tip' 카테고리의 다른 글
| 이벤트 버블 링 및 캡처 란 무엇입니까? (0) | 2020.09.27 |
|---|---|
| virtualenv와 함께 다른 Python 버전 사용 (0) | 2020.09.27 |
| 스크롤 막대를 숨기지 만 여전히 스크롤 할 수 있음 (0) | 2020.09.27 |
| 배열 배열 병합 / 편 평화 (0) | 2020.09.27 |
| 문자열에서 switch 문을 사용할 수없는 이유는 무엇입니까? (0) | 2020.09.27 |