Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost::qvm not usable in boost::spirit::x3 #39

Closed
octopus-prime opened this issue Mar 27, 2022 · 4 comments
Closed

boost::qvm not usable in boost::spirit::x3 #39

octopus-prime opened this issue Mar 27, 2022 · 4 comments

Comments

@octopus-prime
Copy link

If you try to parse
boost::qvm::vec<float, 3>
you fail with compiler errors:

error: conversion from 'boost::qvm::vec<float, 3>' to 'boost::spirit::x3::unused_type' is ambiguous

reason:

/usr/include/boost/qvm/vec.hpp:25:13: note: candidate function [with R = boost::spirit::x3::unused_type]

            operator R() const

            ^

/usr/include/boost/spirit/home/x3/support/unused.hpp:21:9: note: candidate constructor [with T = boost::qvm::vec<float, 3>]

        unused_type(T const&)

        ^
@zajo
Copy link
Collaborator

zajo commented Mar 27, 2022

Can I get a complete short program that demonstrates the problem?

@octopus-prime
Copy link
Author

octopus-prime commented Mar 27, 2022

#include <boost/qvm/vec.hpp>
#include <boost/spirit/home/x3.hpp>

namespace qvm = boost::qvm;
namespace x3 = boost::spirit::x3;

using scalar_t = float;

auto const scalar = x3::rule<struct scalar_, scalar_t>{"scalar"} =
x3::float_;

using vector_t = qvm::vec<scalar_t, 3>;

template <size_t N>
struct foo {
	template <typename C>
	void operator()(C const& ctx) const {
		x3::_val(ctx).a[N] = x3::_attr(ctx);
	}
};

auto const vector = x3::rule<struct vector_, vector_t>{"vector"} =
x3::lit('<') > scalar [foo<0>()] > x3::lit(',') > scalar [foo<1>()] > x3::lit(',') > scalar [foo<2>()] > x3::lit('>');

int main() {
    std::string input = "center = <0,0,0>";
    vector_t result;
    x3::phrase_parse(input.begin(), input.end(), x3::lit("center") > x3::lit('=') > vector > x3::eoi, x3::space, result);
    return 0;
}

Tip: use clang++ because of g++ 'internal compiler error'

@zajo
Copy link
Collaborator

zajo commented Apr 14, 2022

Thanks. Please confirm that this fixes it: https://github.com/boostorg/qvm/tree/feature/issue_39.

@octopus-prime
Copy link
Author

Works like a charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants