Skip to content

Instantly share code, notes, and snippets.

@simmplecoder
Last active November 8, 2016 07:26
Show Gist options
  • Save simmplecoder/18f64552b77ef1884eca24d7af84b23c to your computer and use it in GitHub Desktop.
Save simmplecoder/18f64552b77ef1884eca24d7af84b23c to your computer and use it in GitHub Desktop.
#define EPSILON 0.001
#include <utility>
#include <bitset>
#include <cassert>
#include <iostream>
template <std::size_t dimensions>
using quadrant = std::bitset<dimensions>;
template <typename T>
bool is_negative(const T& t) //specialize if needed
{
return t < 0;
}
template <>
bool is_negative(const double& value)
{
return (value - EPSILON < 0);
}
template <typename ... ArgTypes>
quadrant<sizeof...(ArgTypes)> find_quadrant(ArgTypes&& ... args)
{
bool signs[] = {is_negative(std::forward<ArgTypes>(args))...}; //just turned out that we can expand signof right into the array
quadrant<sizeof...(ArgTypes)> q;
for (std::size_t i = 0; i < sizeof...(ArgTypes); ++i)
{
q[i] = signs[i];
}
return q;
}
int main()
{
double x = 1, y = 1, z = 1;
auto result = find_quadrant(x, y, z);
if (result[0] == false && result[1] == false && result[2] == false)
{
std::cout << "Success!\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment