Skip to content

C++14 support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ endfunction()
# Set standard

function(setStandard target)
target_compile_features(${target} PRIVATE cxx_std_17)
target_compile_features(${target} PRIVATE cxx_std_14)
endfunction()

# Benchmarks
Expand Down Expand Up @@ -80,4 +80,4 @@ option (BUILD_TESTING "Build the testing tree." ON)
if (BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
endif()
10 changes: 5 additions & 5 deletions examples/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct Node
std::vector<Node> generateRandomNodes(std::size_t n)
{
auto generator = std::default_random_engine();
auto originDistribution = std::uniform_real_distribution(0.0f, 1.0f);
auto sizeDistribution = std::uniform_real_distribution(0.0f, 0.01f);
auto originDistribution = std::uniform_real_distribution<float>(0.0f, 1.0f);
auto sizeDistribution = std::uniform_real_distribution<float>(0.0f, 0.01f);
auto nodes = std::vector<Node>(n);
for (auto i = std::size_t(0); i < n; ++i)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ int main()
{
return node->box;
};
auto box = Box(0.0f, 0.0f, 1.0f, 1.0f);
auto box = Box<float>(0.0f, 0.0f, 1.0f, 1.0f);
auto nodes = generateRandomNodes(n);
// Add nodes to quadtree
auto quadtree = Quadtree<Node*, decltype(getBox)>(box, getBox);
Expand All @@ -74,7 +74,7 @@ int main()
quadtree.add(&node);
// Randomly remove some nodes
auto generator = std::default_random_engine();
auto deathDistribution = std::uniform_int_distribution(0, 1);
auto deathDistribution = std::uniform_int_distribution<int>(0, 1);
auto removed = std::vector<bool>(nodes.size(), false);
std::generate(std::begin(removed), std::end(removed),
[&generator, &deathDistribution](){ return deathDistribution(generator); });
Expand Down Expand Up @@ -105,4 +105,4 @@ int main()
std::cout << intersections2.size() << '\n';

return 0;
}
}
12 changes: 10 additions & 2 deletions include/Quadtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ namespace quadtree
template<typename T, typename GetBox, typename Equal = std::equal_to<T>, typename Float = float>
class Quadtree
{
#if __cplusplus < 201703L
static_assert(std::is_convertible<typename std::result_of<GetBox(const T&)>::type, Box<Float>>::value,
#else
static_assert(std::is_convertible_v<std::invoke_result_t<GetBox, const T&>, Box<Float>>,
#endif
"GetBox must be a callable of signature Box<Float>(const T&)");
#if __cplusplus < 201703L
static_assert(std::is_convertible<typename std::result_of<Equal(const T&, const T&)>::type, bool>::value,
#else
static_assert(std::is_convertible_v<std::invoke_result_t<Equal, const T&, const T&>, bool>,
#endif
"Equal must be a callable of signature bool(const T&, const T&)");
static_assert(std::is_arithmetic_v<Float>);
static_assert(std::is_arithmetic<Float>::value, "is_arithmetic<Float> is false");

public:
Quadtree(const Box<Float>& box, const GetBox& getBox = GetBox(),
Expand Down Expand Up @@ -301,4 +309,4 @@ class Quadtree
}
};

}
}
18 changes: 9 additions & 9 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct Node
std::vector<Node> generateRandomNodes(std::size_t n)
{
auto generator = std::default_random_engine();
auto originDistribution = std::uniform_real_distribution(0.0f, 1.0f);
auto sizeDistribution = std::uniform_real_distribution(0.0f, 0.01f);
auto originDistribution = std::uniform_real_distribution<float>(0.0f, 1.0f);
auto sizeDistribution = std::uniform_real_distribution<float>(0.0f, 0.01f);
auto nodes = std::vector<Node>(n);
for (auto i = std::size_t(0); i < n; ++i)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST_P(QuadtreeTest, AddAndQueryTest)
{
return node->box;
};
auto box = Box(0.0f, 0.0f, 1.0f, 1.0f);
auto box = Box<float>(0.0f, 0.0f, 1.0f, 1.0f);
auto nodes = generateRandomNodes(n);
// Add nodes to quadtree
auto quadtree = Quadtree<Node*, decltype(getBox)>(box, getBox);
Expand All @@ -137,7 +137,7 @@ TEST_P(QuadtreeTest, AddAndFindAllIntersectionsTest)
{
return node->box;
};
auto box = Box(0.0f, 0.0f, 1.0f, 1.0f);
auto box = Box<float>(0.0f, 0.0f, 1.0f, 1.0f);
auto nodes = generateRandomNodes(n);
// Add nodes to quadtree
auto quadtree = Quadtree<Node*, decltype(getBox)>(box, getBox);
Expand All @@ -158,15 +158,15 @@ TEST_P(QuadtreeTest, AddRemoveAndQueryTest)
{
return node->box;
};
auto box = Box(0.0f, 0.0f, 1.0f, 1.0f);
auto box = Box<float>(0.0f, 0.0f, 1.0f, 1.0f);
auto nodes = generateRandomNodes(n);
// Add nodes to quadtree
auto quadtree = Quadtree<Node*, decltype(getBox)>(box, getBox);
for (auto& node : nodes)
quadtree.add(&node);
// Randomly remove some nodes
auto generator = std::default_random_engine();
auto deathDistribution = std::uniform_int_distribution(0, 1);
auto deathDistribution = std::uniform_int_distribution<int>(0, 1);
auto removed = std::vector<bool>(nodes.size());
std::generate(std::begin(removed), std::end(removed),
[&generator, &deathDistribution](){ return deathDistribution(generator); });
Expand Down Expand Up @@ -206,15 +206,15 @@ TEST_P(QuadtreeTest, AddRemoveAndFindAllIntersectionsTest)
{
return node->box;
};
auto box = Box(0.0f, 0.0f, 1.0f, 1.0f);
auto box = Box<float>(0.0f, 0.0f, 1.0f, 1.0f);
auto nodes = generateRandomNodes(n);
// Add nodes to quadtree
auto quadtree = Quadtree<Node*, decltype(getBox)>(box, getBox);
for (auto& node : nodes)
quadtree.add(&node);
// Randomly remove some nodes
auto generator = std::default_random_engine();
auto deathDistribution = std::uniform_int_distribution(0, 1);
auto deathDistribution = std::uniform_int_distribution<int>(0, 1);
auto removed = std::vector<bool>(nodes.size());
std::generate(std::begin(removed), std::end(removed),
[&generator, &deathDistribution](){ return deathDistribution(generator); });
Expand All @@ -238,4 +238,4 @@ int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}