Questions tagged [stdoptional]

In C++ the std::optional class template represents an optional value, i.e. one that may or may not be present.

The C++ class template std::optional<T> represents an optional value of type T, so that either it contains a valid value of type T or it contains nothing.

Related tags

173 questions
-1
votes
1 answer

Why is MSVC trying, and failing, to compile my code as C++14?

In a project of mine, I have a header file with the following code: #if __cplusplus >= 201703L #include #include namespace foo { using ::std::optional; using ::std::nullopt; } // namespace foo #elif __cplusplus >= 201402L #include…
-1
votes
2 answers

How to access members inside vector of structure

I have a member variable which is of type vector of structure and which is defined as std::optional, so how do I access members inside the structure. Example: std::optional> mem_variable; struct demoStruct { int a; float…
-1
votes
3 answers

Is there a way of creating an std::optional<> out of a nullable argument?

Languages such as Scala and Java have had for quite some time some sort of optional type. In both, there seems to be a constructor method allowing one to either pass in an object O or a null value. The first constructs an optional value with a copy…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
-1
votes
2 answers

How to correctly check any_cast available?

I have some input which can be simple value or container, packed in std::any. I don't want to use exceptions, so I call noexcept variadic any_cast method which return pointer or nullptr to value of any. I can verify any cast available with typeid()…
-1
votes
1 answer

Return std::nullopt as a non-constant reference

Form academic point of view, if I wanted to return std::nullopt as a non-constant reference. How will I be doing the same. Little background, today when I was working on a code returning an std::optional> reference but I forgot to make the return…
Dark Sorrow
  • 1,681
  • 14
  • 37
-3
votes
0 answers

Calling pure virtual method is jumping to wrong functions

In below scenario for class xyz I am facing some issue when I call method2 and keep breakpoint to called place at method1 its jumping to the middle method1 having the extra std::optional argument class xyz { public: virtual int method(int, int)…
user2621476
  • 93
  • 1
  • 8
-3
votes
1 answer

Why does std::optional have a special equality operator for operand of the type std::nullopt

The class template std::optional has the conversion constructor constexpr optional(nullopt_t) noexcept; So a question arises why is there declared the special single equality operator in the C++ Standard template constexpr bool…
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
-6
votes
1 answer

Does C++ standardize the behavior of std::optional under std::min and std::max?

I don't have a very recent compiler installed to get a hint of what the final std::optional semantics are going to be. But in C++14, the following: #include #include int main() { using oint =…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1 2 3
11
12