Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Created August 19, 2021 13:35
Show Gist options
  • Save ryutorion/908898411c449689901182b5511f08f3 to your computer and use it in GitHub Desktop.
Save ryutorion/908898411c449689901182b5511f08f3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <format>
using namespace std;
void GenerateSwizzle2(const char * input_type, const vector<char> & elements)
{
for(auto vx : elements)
{
for(auto vy : elements)
{
cout << format("[[nodiscard]] inline constexpr const Vector2 {}{}(const {} & v) noexcept", vx, vy, input_type) << std::endl;
cout << "{" << endl;
cout << format("\treturn Vector2(v.{}, v.{});", vx, vy) << endl;
cout << "}" << endl;
cout << endl;
}
}
}
void GenerateSwizzle3(const char * input_type, const vector<char> & elements)
{
for(auto vx : elements)
{
for(auto vy : elements)
{
for(auto vz : elements)
{
cout << format("[[nodiscard]] inline constexpr const Vector3 {}{}{}(const {} & v) noexcept", vx, vy, vz, input_type) << std::endl;
cout << "{" << endl;
cout << format("\treturn Vector3(v.{}, v.{}, v.{});", vx, vy, vz) << endl;
cout << "}" << endl;
cout << endl;
}
}
}
}
void GenerateSwizzle4(const char * input_type, const vector<char> & elements)
{
for(auto vx : elements)
{
for(auto vy : elements)
{
for(auto vz : elements)
{
for(auto vw : elements)
{
cout << format("[[nodiscard]] inline constexpr const Vector4 {}{}{}{}(const {} & v) noexcept", vx, vy, vz, vw, input_type) << std::endl;
cout << "{" << endl;
cout << format("\treturn Vector4(v.{}, v.{}, v.{}, v.{});", vx, vy, vz, vw) << endl;
cout << "}" << endl;
cout << endl;
}
}
}
}
}
void GenerateSwizzleVector2()
{
const vector<char> elements { 'x', 'y' };
GenerateSwizzle2("Vector2", elements);
GenerateSwizzle3("Vector2", elements);
GenerateSwizzle4("Vector2", elements);
}
void GenerateSwizzleVector3()
{
const vector<char> elements { 'x', 'y', 'z' };
GenerateSwizzle2("Vector3", elements);
GenerateSwizzle3("Vector3", elements);
GenerateSwizzle4("Vector3", elements);
}
void GenerateSwizzleVector4()
{
const vector<char> elements { 'x', 'y', 'z', 'w' };
GenerateSwizzle2("Vector4", elements);
GenerateSwizzle3("Vector4", elements);
GenerateSwizzle4("Vector4", elements);
}
int main(int argc, const char * argv[])
{
GenerateSwizzleVector2();
GenerateSwizzleVector3();
GenerateSwizzleVector4();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment