This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I'm working on a compiler for one of the courses I need for my degree and I need to modify a major part of it (the expression evaluator) to handle optional references (I could just overload the entire thing but I don't want to duplicate code and create more work for myself). I came across std::reference_wrapper
(and its helper functions, std::ref
and std::cref
). My question is: is it legal and okay to create an std::optional<std::reference_wrapper<T>>
as a function parameter (since an std::optional<T&>
is illegal)? If I, say, have an std::optional<std::reference_wrapper<std::stringstream>>
and I want to write data to it and have that data remain when I return to the caller, would it be fine to use that (std::optional<std::reference_wrapper<std::stringstream>>
) when declaring the function, or is this bad practice? Is there some better way I can use (while trying to avoid pointers)?
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...