Skip to content

construction, comparisons broken #96

Closed

Description

@vinniefalco

Lines 14 and 15 do not compile:
https://godbolt.org/z/cejhMT6z8

#include <optional>
#include <string_view>
#include <boost/optional.hpp>
#include <boost/utility/string_view.hpp>

int main()
{
    int n = 0;

    std::optional<std::string_view> v1 = "test";
    if( v1 == "test" )
        n |= 1;

    boost::optional<std::string_view> v2 = "test";
    if( v2 == "test ")
        n |= 2;

    return n;
}

Activity

  1. akrzemi1 commented on Sep 13, 2024

    @akrzemi1
    Member

    This isn't really a bug. boost::optional works according to its specification. It is just it's specification is different than std::optional. boost::optional doesn't aim at 100% compatibility with std::optional, because the latter has design flaws that I do not want to repeat.

    For now, you need to trust me on this. I will add the section in the docs describing the differences between boost::optional and std::optional along with the rationale, and then hopefully this will be clear.

  2. vinniefalco commented on Sep 13, 2024

    @vinniefalco
    MemberAuthor

    That's fair, but in my mind this:

    if( opt == X )
    

    Should be a simple shortcut for

    if( opt.has_value() && *opt == X )
    

    Why shouldn't this work?

  3. akrzemi1 commented on Sep 13, 2024

    @akrzemi1
    Member

    Not directly an answer to your question, but this should give you an idea about where I am coming from from:
    https://akrzemi1.wordpress.com/2018/12/09/deducing-your-intentions/

  4. vinniefalco commented on Sep 14, 2024

    @vinniefalco
    MemberAuthor

    Peter doesn't like it either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions