[SERVER-24216] Add static factory function to Duration that does not throw Created: 19/May/16  Updated: 06/Dec/22  Resolved: 24/Jun/19

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

Type: Improvement Priority: Major - P3
Reporter: Matt Cotter Assignee: DO NOT USE - Backlog - Dev Tools
Resolution: Won't Fix Votes: 0
Labels: platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Developer Tools
Participants:

 Description   

Ex:

int ms = 12341234;
auto millis = representAs<Milliseconds>(ms);
 
// use case I want:
fn( representAs<Milliseconds>(userInputMs).value_or(Milliseconds::max()) );



 Comments   
Comment by Sara Williamson [ 24/Jun/19 ]

Closing this for now, but if a use case arises this ticket can be re-opened.

Comment by Mark Benvenuto [ 21/Dec/16 ]

Another possible design option is to use StatusWith<> instead of optional<>

template <typename Rep2>
static StatusWith<Duration> fromCount(const Rep2& count)?

If there is not motivating example though, I do not see why this is related a C++14 code base

Comment by Matt Cotter [ 20/May/16 ]

That sounds good to me.

Comment by Andy Schwerin [ 20/May/16 ]

I don't think representAs should convert from unitless number types to Duration. Maybe a static factory function on Duration?

template <typename Rep2>
static optional<Duration> fromCount(const Rep2& count)?

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