Giter VIP home page Giter VIP logo

Comments (8)

felixguendling avatar felixguendling commented on May 20, 2024 2

Thank you very much for your report.

I hope I fixed it (it's on master):

template <class T, class... Ts>
constexpr std::add_pointer_t<T> get_if(cista::variant<Ts...>& v) noexcept {
static_assert(cista::index_of_type<T, Ts...>() != cista::TYPE_NOT_FOUND);
return v.idx_ == cista::index_of_type<T, Ts...>() ? &v.template as<T>()
: nullptr;
}

from cista.

ChemistAion avatar ChemistAion commented on May 20, 2024

I have better issue description from gcc, here below:

return v.idx_ == &cista::index_of_type<T, Ts...> ? v.template as<T>()

quote:
[pointing on "=="]
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
return v.idx_ == &cista::index_of_type<T, Ts...> ? v.template as()

[pointing on "?"]
error: operands to '?:' have different types 'bool' and 'std::nullptr_t'
return v.idx_ == &cista::index_of_type<T, Ts...> ? v.template as()

from cista.

ChemistAion avatar ChemistAion commented on May 20, 2024

Whoa! That was quick... :)

from cista.

ChemistAion avatar ChemistAion commented on May 20, 2024

Almost :)

It works until recurring reference container is added to the variant, i.e. CISTA::unique_ptr<Test> below:

struct Test;

using Variant = CISTA::variant
	<
	bool,
	std::int64_t,
	std::uint64_t,
	double,
	CISTA::string,
	CISTA::unique_ptr<int>,
	CISTA::unique_ptr<Test>
	>;

struct Test : public CISTA::vector<Variant>
{
};

////////////////////////////////////////////////////////////////////////////////

Variant test{ true };
auto result = cista::get_if<bool>(test);

Same errors on MSVS

from cista.

felixguendling avatar felixguendling commented on May 20, 2024

This test case works for me:

TEST_CASE("variant get_if") {
  namespace CISTA = cista::offset;
  struct Test;

  using Variant =
      CISTA::variant<bool, std::int64_t, std::uint64_t, double, CISTA::string,
                     CISTA::unique_ptr<int>, CISTA::unique_ptr<Test>>;

  struct Test : public CISTA::vector<Variant> {};

  Variant test{true};
  auto const result = cista::get_if<bool>(test);
  REQUIRE(result != nullptr);
  CHECK(*result == true);

  test = CISTA::string{"hello test test test test"};
  auto const str = cista::get_if<CISTA::string>(test);
  REQUIRE(str != nullptr);
  CHECK(*str == "hello test test test test");
}

Checking to see if it breaks in GitHub Actions.
da8da3a

Edit: seems the CI build works
https://github.com/felixguendling/cista/actions/runs/1035547916

from cista.

ChemistAion avatar ChemistAion commented on May 20, 2024

btw: cista::get_if<>(const& v) should be also patched:

template <class T, class... Ts>
constexpr std::add_pointer_t<T const> get_if(
cista::variant<Ts...> const& v) noexcept {
static_assert(cista::index_of_type<T, Ts...>() != cista::TYPE_NOT_FOUND);
return v.idx_ == cista::index_of_type<T, Ts...> ? &v.template as<T>()
: nullptr;
}

from cista.

felixguendling avatar felixguendling commented on May 20, 2024

Should be fixed now by eb050ae

from cista.

ChemistAion avatar ChemistAion commented on May 20, 2024

Indeed, thank you.

from cista.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.