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

X3: Use traits to test if container is empty #355

Merged
merged 1 commit into from
Jan 24, 2018
Merged

X3: Use traits to test if container is empty #355

merged 1 commit into from
Jan 24, 2018

Conversation

timangus
Copy link
Contributor

::empty() is called on the Attribute in parse_into_container_impl. If Attribute has no ::empty(), if fails to compile. Probably instead it should use traits::is_empty(...).

@timangus timangus changed the title Use traits to detect test container is empty Use traits to test if container is empty Jan 24, 2018
@Kojoley
Copy link
Collaborator

Kojoley commented Jan 24, 2018

Do you specialize traits::is_empty for your custom container because it does not expose empty method (but use some other way to determine if it is empty)?
I mostly see traits::is_empty is used to deal with unused_type, but parse_into_container_impl::call have override for it (added in ee4943d). Can you please provide a test case?

@timangus
Copy link
Contributor Author

Ah right, I'll admit I was testing using 1.66 rather than the develop branch; it looks like ee4943d would resolve my problem albeit in a different way. FWIW, my custom container is QString, and my traits are:

namespace boost { namespace spirit { namespace x3 { namespace traits {

template<>
struct push_back_container<QString>
{
    template<typename T>
    static bool call(QString& c, T&& val)
    {
        c.push_back(std::move(val));
        return true;
    }
};

template<>
struct append_container<QString>
{
    template<typename Iterator>
    static bool call(QString& c, Iterator first, Iterator last)
    {
        c.append(first, std::distance(first, last));
        return true;
    }
};

template<>
struct is_empty_container<QString>
{
    static bool call(QString const& c)
    {
        return c.isEmpty();
    }
};

}}}}

@timangus
Copy link
Contributor Author

timangus commented Jan 24, 2018

Hmm well, quickly patching ee4943d into my code doesn't fix the problem. It does seem like traits is the answer to be honest, it seems to have been in issue #287, whose fix is in the same function.

@Kojoley
Copy link
Collaborator

Kojoley commented Jan 24, 2018

It does seem like traits is the answer to be honest

Yeah. I have asked the first question just to be sure you are using a custom container and we are not fixing some hidden problem with the patch.

@timangus
Copy link
Contributor Author

Ah right, cool. Thanks.

@djowel
Copy link
Collaborator

djowel commented Jan 24, 2018

👍

@Kojoley Kojoley changed the title Use traits to test if container is empty X3: Use traits to test if container is empty Jan 24, 2018
@Kojoley Kojoley merged commit e9e3c35 into boostorg:develop Jan 24, 2018
@Kojoley
Copy link
Collaborator

Kojoley commented Jan 24, 2018

Thanks for patch, and for Tremulous!

@timangus
Copy link
Contributor Author

Haha, you're welcome! Believe it or not a small number of people still play it.

@Kojoley
Copy link
Collaborator

Kojoley commented Jan 25, 2018

Nice to hear this! I had not played it since 2011 because of server population drop (it was hard to gather together even 2x2).

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

Successfully merging this pull request may close these issues.

3 participants