[SERVER-51888] Add TS2's std::is_detected etc API to stdx Created: 30/Oct/20  Updated: 29/Oct/23  Resolved: 31/Oct/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-34304 matchers for use in assertion conditions Backlog
Backwards Compatibility: Fully Compatible
Sprint: Service arch 2020-11-02
Participants:

 Description   

It's a pre-standard API. This is what stdx is for.
It would be useful for simplifying decltype-based traits in logv2 and elsewhere.
I needed it for ASSERT_THAT during Skunkworks, so I might as well bring it into stdx.

https://en.cppreference.com/w/cpp/experimental/is_detected



 Comments   
Comment by Githook User [ 01/Nov/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-51888 workaround msvc expression-sfinae access bug

https://developercommunity.visualstudio.com/content/problem/936367/sfinae-sees-private-part-of-a-class.html
Branch: master
https://github.com/mongodb/mongo/commit/0b6e0b281fe9e07ccfd6e041a5e3fe613e885e6d

Comment by Billy Donahue [ 31/Oct/20 ]

MSVC bug that expression sfinae doesn't consider access modifiers.

So a private member function will incorrectly pass a detection idiom check. Then trying to call that function of course fails as usual. So you can't use is_detected on MSVC to correctly identify whether an object has a callable member function. It might have a private member function that would match the decltype call expression, and is_detected will indicate that it's callable anyway. I worked around it here by making a private function in ReplSetConfig public. It was an oversight anyway, but really I just got lucky.

Comment by Githook User [ 31/Oct/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-51888 stdx::is_detected and related traits

ReplSetConfigBase now needs a public serialize to work around MSVC bug
Branch: master
https://github.com/mongodb/mongo/commit/6672b855264f466cc1ea7c911ea1942aabb42f14

Comment by Billy Donahue [ 30/Oct/20 ]

CR https://mongodbcr.appspot.com/695310031

Comment by Billy Donahue [ 30/Oct/20 ]

taking this on as a prereq of skunkworks ASSERT_THAT project

Generated at Thu Feb 08 05:26:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.