Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////
- /// \brief Unroll the expression given.
- /////////////////////////////////////////////////////////////////////
- template ExprUnroll(alias Code, alias Size, alias Op="") {
- enum t = replace(Code, "%", "%1$d");
- enum ExprUnroll = iota(Size).map!(i => format(t, i)).join(Op);
- }
- /////////////////////////////////////////////////////////////////////
- /// \brief Define a mathematic vector.
- ///
- /// \author Wolftein <wolftein@ghrum.org>
- /////////////////////////////////////////////////////////////////////
- public struct Vector(T, size_t Dimension) {
- /// \brief The array that contain the components of the vector.
- private T component[Dimension];
- /// \brief The lenght of the vector.
- private immutable size_t size = Dimension;
- /////////////////////////////////////////////////////////////////////
- /// \brief
- ///
- /// \param[in] vector
- ///
- /// \return
- /////////////////////////////////////////////////////////////////////
- public Vector!(T, size) opAdd(auto ref Vector!(T, size) vector)
- in {
- assert(vector !is null, "Vector cannot be null");
- assert(vector.size() != size(), "Vector differ size");
- }
- body {
- mixin( ExprUnroll!("component[%] += vector.component[%]", Dimension));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement