Giter Club home page Giter Club logo

Comments (5)

wilzbach avatar wilzbach commented on June 20, 2024

Thanks a lot for the ping.
I added a quick fix from my phone: #262

I don't know how this passed and got through our CI systems, but I will investigate once I am back home in a few days.

from english.

SMietzner avatar SMietzner commented on June 20, 2024

You've added extra curly brackets in the switch statement, and it does compiles now.
The reason for this should be explained in description, because it is not obvious why these are mandatory.

from english.

SMietzner avatar SMietzner commented on June 20, 2024

I would propose this as example code:

import std.algorithm, std.conv, std.range,
        std.stdio, std.traits;
struct Config
{
    int runs, port;
    string name;
}
void main()
{
    Config conf;
    // use the generated parser for each entry
    "runs=1,port=2,name=hello"
        .splitter(",")
        .each!(e => conf.parse(e));
    conf.writeln;
}
void parse(Conf)(ref Conf c, string entry)
{
    auto r = entry.splitter("=");
    auto key = r.front, value = r.dropOne.front;
    Switch: switch (key)
    {
        static foreach (idx, field; Conf.tupleof)
        { 
            case field.stringof:
                c.tupleof[idx] =value.to!(typeof(field));
                break Switch;
        }
        default:
        assert (0, "Unknown member name.");
    }
}

from english.

wilzbach avatar wilzbach commented on June 20, 2024

Good idea. I just wanted to fix it.
Would you mind opening a PR for your proposed improvement?
(it's really hard to do this from my phone and I am still backpacking for a few days)

from english.

 avatar commented on June 20, 2024

works for me

from english.

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.