Code Monkey home page Code Monkey logo

Comments (3)

gecko0307 avatar gecko0307 commented on May 26, 2024

Found quick non-duplicating solution, seems like it works. Needs testing thought.

template opDispatch(string s) if (valid(s))
{
    static if (s.length == 1)
    {
        enum i = ["x":0, "y":1, "z":2, "w":3,
                  "r":0, "g":1, "b":2, "a":3,
                  "s":0, "t":1, "p":2, "q":3][s];

        @property auto ref opDispatch(this X)()
        {
            return arrayof[i];
        }

        @property auto ref opDispatch(this X, V)(auto ref V v)
        {
            return arrayof[i] = v;
        }
    }
    else
    static if (s.length <= 4)
    {
        @property auto ref opDispatch(this X)()
        {
            auto extend(string s) 
            {
                while (s.length < 4) 
                    s ~= s[$-1];
                return s;
            }

            enum p = extend(s);
            enum i = (char c) => ['x':0, 'y':1, 'z':2, 'w':3,
                                  'r':0, 'g':1, 'b':2, 'a':3,
                                  's':0, 't':1, 'p':2, 'q':3][c];
            enum i0 = i(p[0]), 
                 i1 = i(p[1]), 
                 i2 = i(p[2]), 
                 i3 = i(p[3]);

            static if (s.length == 4)
                return Vector!(T,4)(arrayof[i0], arrayof[i1], arrayof[i2], arrayof[i3]);
            else static if (s.length == 3)
                return Vector!(T,3)(arrayof[i0], arrayof[i1], arrayof[i2]);
            else static if (s.length == 2)
                return Vector!(T,2)(arrayof[i0], arrayof[i1]);
        }
    }
}

from dlib.

minexew avatar minexew commented on May 26, 2024

Works for me as well, though my code is nowhere near being a stress-test. I'll check if any other methods have this problem.

from dlib.

gecko0307 avatar gecko0307 commented on May 26, 2024

OK, did some tests, compiled my current projects with this, seems fine. Committing.

from dlib.

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.