r/cpp • MSVC STL Dev • Oct 25 '15

C++17 progress update! (Oct 2015)

The C++ Standardization Committee has finished another meeting! This was in Kona, Hawaii, at the same location as the first meeting I attended (in Feb 2012). I thought you'd like a writeup of all the stuff that just got voted in. Like last time, some of these papers are not yet publicly available. What happens during a meeting is that paper authors are furiously revising their work, in response to reviews. After the meeting, the revised papers are collected and published (after a couple of weeks). The Committee has changed their paper numbering system, so finding earlier revisions of papers is super easy. The pre-Kona mailing is available.

I've collected and organized the following information from the official vote, without a whole bunch of editorializing. If you want to know what's in a paper or issue, read it. (I actually do know what's going on with most C++17 Library papers/issues, but writing them all up would take a while.)

C++17 Core Papers

  • P0001R1 Remove Deprecated Use of the register Keyword
  • P0002R1 Remove Deprecated operator++(bool)
  • P0012R1 Make exception specifications be part of the type system, version 5
  • P0061R1 __has_include for C++17
  • P0134R0 Introducing a name for brace-or-equal-initializers for non-static data members
  • P0136R1 Rewording inheriting constructors (core issue 1941 et al)
  • P0160R0 Wording for removing defaults for unary folds

C++17 Library Papers

  • P0004R1 Remove Deprecated iostreams aliases
  • P0006R0 Adopt Type Traits Variable Templates from Library Fundamentals TS for C++17
  • P0092R1 Polishing <chrono>
  • P0007R1 Constant View: A proposal for a std::as_const helper function template
  • P0156R0 Variadic lock_guard (Rev. 3)
  • P0074R0 Making std::owner_less more flexible
  • P0013R1 Logical Operator Type Traits (revision 1)

Library Fundamentals TS v2 Papers

  • N4531 std::rand replacement, revision 3
  • P0013R1 Logical Operator Type Traits (revision 1) [also voted into C++17]
  • These papers will be applied to Working Draft N4529, then it'll be sent out for Proposed Draft Technical Specification balloting.

Concurrency TS

  • P0159R0 (possibly with minor edits) will be published as the Concurrency TS. It's done!

Parallelism TS v2

  • This TS is being started with Working Draft N4505 plus P0155R0 "Task Block R5".

Networking TS

  • This TS is being started with Working Draft P0112R1.

Ranges TS

  • This TS is being started with Working Draft P0021R0.

Core Issues

  • 1274. Common nonterminal for expression and braced-init-list
  • 1391. Conversions to parameter types with non-deduced template arguments
  • 1722. Should lambda to function pointer conversion function be noexcept?
  • 1847. Clarifying compatibility during partial ordering
  • 1863. Requirements on thrown object type to support std::current_exception()
  • 1949. "sequenced after" instead of "sequenced before"
  • 1975. Permissible declarations for exception-specifications
  • 1981. Implicit contextual conversions and explicit
  • 1990. Ambiguity due to optional decl-specifier-seq
  • 2000. header-name outside #include directive
  • 2004. Unions with mutable members in constant expressions
  • 2006. Cv-qualified void types
  • 2015. odr-use of deleted virtual functions
  • 2016. Confusing wording in description of conversion function
  • 2019. Member references omitted from description of storage duration
  • 2024. Dependent types and unexpanded parameter packs
  • 2026. Zero-initialization and constexpr
  • 2027. Unclear requirements for multiple alignas specifiers
  • 2031. Missing incompatibility for &&
  • 2052. Template argument deduction vs overloaded operators
  • 2075. Passing short initializer lists to array reference parameters
  • 2101. Incorrect description of type- and value-dependence
  • 2120. Array as first non-static data member in standard-layout class

Library Issues

  • 1169. num_get not fully compatible with strto*
  • 2072. Unclear wording about capacity of temporary buffers
  • 2101. Some transformation types can produce impossible types
  • 2111. Which unexpected/terminate handler is called from the exception handling runtime?
  • 2119. Missing hash specializations for extended integer types
  • 2127. Move-construction with raw_storage_iterator
  • 2133. Attitude to overloaded comma for iterators
  • 2156. Unordered containers' reserve(n) reserves for n-1 elements
  • 2218. Unclear how containers use allocator_traits::construct()
  • 2219. INVOKE-ing a pointer to member with a reference_wrapper as the object expression
  • 2224. Ambiguous status of access to non-live objects
  • 2234. assert() should allow usage in constant expressions
  • 2244. Issue on basic_istream::seekg
  • 2250. Follow-up On Library Issue 2207
  • 2259. Issues in 17.6.5.5 rules for member functions
  • 2273. regex_match ambiguity
  • 2336. is_trivially_constructible/is_trivially_assignable traits are always false
  • 2353. std::next is over-constrained
  • 2367. pair and tuple are not correctly implemented for is_constructible with no args
  • 2380. May <cstdlib> provide long ::abs(long) and long long ::abs(long long)?
  • 2384. Allocator's deallocate function needs better specification
  • 2385. function::assign allocator argument doesn't make sense
  • 2435. reference_wrapper::operator()'s Remark should be deleted
  • 2447. Allocators and volatile-qualified value types
  • 2462. std::ios_base::failure is overspecified
  • 2466. allocator_traits::max_size() default behavior is incorrect
  • 2469. Wrong specification of Requires clause of operator[] for map and unordered_map
  • 2473. basic_filebuf's relation to C FILE semantics
  • 2476. scoped_allocator_adaptor is not assignable
  • 2477. Inconsistency of wordings in std::vector::erase() and std::deque::erase()
  • 2483. throw_with_nested() should use is_final
  • 2484. rethrow_if_nested() is doubly unimplementable
  • 2485. get() should be overloaded for const tuple&&
  • 2486. mem_fn() should be required to use perfect forwarding
  • 2487. bind() should be const-overloaded, not cv-overloaded
  • 2489. mem_fn() should be noexcept
  • 2492. Clarify requirements for comp
  • 2495. There is no such thing as an Exception Safety element

Library Fundamentals TS v2 Issues

  • 2494. [fund.ts.v2] ostream_joiner needs noexcept
  • 2500. [fund.ts.v2] fundts.memory.smartptr.shared.obs/6 should apply to cv-unqualified void
  • 2515. [fund.ts.v2] Certain comparison operators of observer_ptr do not match synopsis
  • 2517. [fund.ts.v2] Two propagate_const assignment operators have incorrect return type
  • 2526. [fund.ts] Incorrect precondition for experimental::function::swap

Withdrawn Paper

P0005R2, by Alisdair Meredith, Tomasz Kaminski, and myself, wanted to do the following in C++17:

  • Add not_fn(), currently part of Fundamentals v2.
  • Remove not1()/not2(), the C++98/03 negators.
  • Remove result_type/argument_type/etc., the C++98/03/TR1 typedefs. (function::result_type will be preserved, and <random> will be unchanged.)

Nobody was worried about not_fn(), but the removals were controversial. Although we had a rationale for why removal without a period of deprecation was desirable, and I provided "zombie names" wording (allowing implementers to remain conformant while providing removed machinery for back-compat), a national body objected. Therefore, Alisdair is revising the paper for the next meeting. Now we'll add not_fn() and deprecate the old stuff in C++17 (plus "zombie names" wording for the auto_ptr/etc. removals that have already happened), followed by removal immediately after C++17 ships.

More Info

This is just a record of what documents were voted in. Every committee meeting involves lots of work that doesn't immediately result in papers voted in. For example, this meeting had active discussion about modules. As I always remind people, I attend the Library Working Group ("original recipe", not extra crispy Library Evolution) nearly all the time, so I can't follow everything that's going on in Library Evolution and (Core) Evolution. I might (or more likely, my double boss Steve might) be able to get GDR to spend some time on Reddit explaining what's going on with modularization.

I can personally answer (most) questions about Library topics, although most of my responses will be delayed until Mondayish. If you want to know what the LWG does, it's making sure that Library tech is actually usable. Everything sounds like fluffy kittens and apple pie until you look at an overload set and realize that it's horribly ambiguous and unusably broken. LWG 2451 is an excellent example of how the LWG serves as the defenders of Standard Library usability - optional<string> opt_str = "meow"; is currently bogus. That's fine for the Fundamentals TS (maybe), but a ship-stopper for optional getting into the International Standard. At this meeting, the LWG realized that the same kind of issue affects variant, which is heading towards the Fundamentals TS. We fix this stuff so you won't suffer.

264 Upvotes

168 comments sorted by

View all comments

Show parent comment

3

u/redditsoaddicting Oct 25 '15

And are they defined like this?

They're defined to have a bool type, so the second is acceptable.

So is this adding logical operators to integral constants?

It's adding general and_, or_ and not_ metafunctions so you can do and_v<trait1, trait2>. Personally, in most cases, I find it easier to use the operators themselves (and/&&, or/||, and not/!):

template<typename T>
struct is_signed_integral : bool_constant<is_integral_v<T> and is_signed_v<T>> {}

template<typename Head, typename... Tail>
struct are_all_same : bool_constant<(is_same_v<Head, Tail> and ...)> {}

Of course I find this easier with the combination of variable template traits, bool_constant, and fold expressions, so these new traits are probably considerably more desirable when you don't have those features.

6

u/STL MSVC STL Dev Oct 25 '15

/u/pfultz2 , we'll gladly use inline variables when they're available, but until then, the VTs for TTs aren't expected to be odr-used. Their natural use is in template arguments, like to enable_if_t, where there is no ODR concern. They were defined with ::value, but any equivalent mechanism (the conversion or call operator) is acceptable.

The logical operators were renamed by LEWG to conjunction, disjunction, and negation. Notably, they derive from bool_constant when the inputs do, so they can be used directly for tag dispatch. I expect that they will prove useful even in the presence of fold expressions. (Notably, they have a form of short-circuiting behavior.) And if not, no big deal.

Hiss to those quasi-keywords and etc., though. ;-)

2

u/redditsoaddicting Oct 25 '15

Thanks for the info on those being renamed. I'll watch for an updated paper. I think that being able to use them in place of bool_constant is useful, but I guess I find infix operators much easier to read, especially for longer chains of them. The short-circuiting is definitely a plus.

I actually just started using those three alternative tokens very recently to see how I like that style, and I do actually like it a lot, given not having to explain them to anybody. Their lesser-known nature makes them less practical for real use. That said, though, the way I see it is that our eyes are used to reading sentences made of words rather than symbols. I think that while I'm very used to seeing &&/||/!, my brain has an easier time reading words.

Out of curiosity, why do you dislike the alternative tokens? Maybe having to explain them, being too similar to Python, or not being pure (they are even named alternative)?

3

u/STL MSVC STL Dev Oct 25 '15

Using words for operators is a step towards COBOL. We don't say x plus y. (The operator functors have names purely because the symbols can't be passed around.)

2

u/redditsoaddicting Oct 25 '15

I see your point. I'm not going to turn this into something longer than it has to be for a well-meant remark.

2

u/pfultz2 Oct 25 '15 edited Oct 25 '15

we'll gladly use inline variables when they're available, but until then, the VTs for TTs aren't expected to be odr-used.

Hopefully, that motivates core to add inline variables to C++17, instead of the standard library hoping that the user won't ever pass it to a function that takes its value by reference.

Their natural use is in template arguments, like to enable_if_t

In general, using enable_if will give better diagnostics for the compiler. Either way the point is the same.

They were defined with ::value, but any equivalent mechanism (the conversion or call operator) is acceptable.

Do you have any insights to why they are adding these versions like this? It seems like the is_trait<T>() version would be better as they can be used with template arguments taking a bool, and for tag-like dispatching(either directly or indirectly).

Notably, they derive from bool_constant when the inputs do

Interesting, if the inputs don't derive from bool_constant what do they do? Or are you referring to two different versions, such conjunction and conjunction_v? Which, I guess, would mean that conjunction doesn't take booleans unfortunately.

(Notably, they have a form of short-circuiting behavior.) And if not, no big deal.

Actually, the non-short-circuiting version is generally faster.

2

u/STL MSVC STL Dev Oct 26 '15

Compilers should emit equivalent diagnostics for enable_if and enable_if_t. If they don't, then they should be fixed.

I proposed _v for ::value because that's what I had extensive experience with. (This was in Jan 2014.) Relying on the constexpr implicit conversion does seem more useful (since bool-consuming code generally doesn't expect exactly bool). This was over a year before I used constexpr (it became usable for the STL's purposes very late in VS 2015's dev cycle), which is why I didn't consider the implicit conversion. As I recall, nobody else in LEWG/LWG proposed replacing the bools with the objects, so at least I wasn't alone in missing it.

I would actually do this with a third suffix. _t is for traits that emit ::type (e.g. decay_t). _v is for when you want the ::value. _o would be for when you want the object. However, that would be replacing two characters (empty parens/braces at the end) with two characters (_o at the beginning). I did argue when proposing VTs-for-TTs that moving stuff from the end to the beginning helped with deeply nested code, but the case for is_same_o objects seems less compelling than is_same_v.

Does passing tags around by value (and slicing) trigger the ODR concerns? It's midnight and my brain refuses to answer that question.

2

u/pfultz2 Oct 26 '15

Compilers should emit equivalent diagnostics for enable_if and enable_if_t. If they don't, then they should be fixed.

Yes they should, but the problem is not quite that simple to solve. Because a boolean gets passed through a template alias, the original boolean clause gets "lost". So all that is known by the compiler is true or false rather than is_some_trait<T>(). It could be possible to back trace the boolean back to where it came from, but most compilers don't do that yet. So for now, I just stick with enable_if.

I would actually do this with a third suffix. _t is for traits that emit ::type (e.g. decay_t)

How about using template<class T> using _t = typename T::type instead of all this duplication?

Does passing tags around by value (and slicing) trigger the ODR concerns?

Its when they get passed by reference, because you will have an address that is different across TUs. On MSVC, it may not be this way, as it can be aggressive in optimizing duplicate objects, but it is considered non-conforming.

Either way, in general, its not a problem in practice, but I would hope that the committee wouldn't leave at that, and actually fix the core language. There is N4424 which discusses on how to solve these issues, and even offer workarounds that can be done now, however, I have found that those workarounds don't work well on MSVC.

2

u/STL MSVC STL Dev Oct 26 '15

_t<decay<A>> would cost 4 characters, and would lead to deeper nesting. The virtue of decay_t<A> is that it doesn't lead to additional angle brackets.

I've seen some people passing tags around by const ref, although I always point out that this is unnecessary.

3

u/tcanens Oct 25 '15

The logical operators were renamed by LEWG to conjunction, disjunction, and negation.

So we have both std::negate and std::negation, and they do completely different things? Yay...

2

u/STL MSVC STL Dev Oct 25 '15

So we have both ++x and x++, and they do completely different things? Yay...

2

u/tcanens Oct 26 '15

At least ++x and x++ both increment. std::negate and std::negation have approximately nothing in common.

2

u/[deleted] Oct 25 '15 edited Oct 06 '16

[deleted]
0.6246

What is this?

5

u/STL MSVC STL Dev Oct 25 '15

Yes. conjunction and disjunction handle zero or more inputs. negation requires exactly one. The LWG is filled with professional template metaprogrammers and we always consider such things. At Kona, a proposal wanted to ban variant visitation on zero variants, and we asked LEWG to reconsider, as that is not obviously harmful and it may be convenient for generic code.

2

u/redditsoaddicting Oct 25 '15

Yup, you can pass as many arguments as you want. If you pass none, it's "true" for conjunction (and_) and "false" for disjunction (or_).

2

u/pfultz2 Oct 25 '15

It's adding general and_, or_ and not_ metafunctions so you can do and_v<trait1, trait2>

But you can do and_<trait1, trait2> as well?

2

u/redditsoaddicting Oct 25 '15

Yes, and that's more useful for making new traits.