Skip to content

Commit 1847ed9

Browse files
committed
feat: get rid of custom index_sequence
1 parent a880539 commit 1847ed9

11 files changed

+74
-89
lines changed

CMakeLists.txt

+29-6
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,45 @@ else()
2323
set(PROJECT_VERSION ${_pversion})
2424
endif()
2525

26-
option(BUILD_TESTS "Build tests for ${lib_name} library" ON)
27-
option(BUILD_BENCHMARKS "Build benchmarks for ${lib_name} library" ON)
26+
option(PSST_MATH_BUILD_TESTS "Build tests for ${lib_name} library" ON)
27+
option(PSST_MATH_BUILD_BENCHMARKS "Build benchmarks for ${lib_name} library" ON)
2828

2929
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
3030

31-
add_definitions("-std=c++11")
32-
add_definitions(-Wall -Werror -pedantic)
31+
set(CMAKE_CXX_STANDARD 17)
32+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33+
34+
add_definitions(-Wall -Werror -Wpedantic)
35+
36+
option(USE_CCACHE "Use ccache for build" ON)
37+
if (USE_CCACHE)
38+
find_program(CCACHE ccache)
39+
if (CCACHE)
40+
message(STATUS "ccache found and enabled")
41+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
42+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
43+
else()
44+
message(WARNING "ccache enabled, but not found")
45+
endif()
46+
else()
47+
message(STATUS "ccache disabled")
48+
endif()
49+
50+
3351
add_subdirectory(include)
3452

3553
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
36-
if (BUILD_TESTS)
54+
55+
if (PSST_MATH_BUILD_TESTS OR PSST_MATH_BUILD_BENCHMARKS)
56+
find_package(ExternalProjectZmijModules)
57+
endif()
58+
59+
if (PSST_MATH_BUILD_TESTS)
3760
enable_testing()
3861
add_subdirectory(test)
3962
endif()
4063

41-
if (BUILD_BENCHMARKS)
64+
if (PSST_MATH_BUILD_BENCHMARKS)
4265
enable_testing()
4366
add_subdirectory(benchmark)
4467
endif()

benchmark/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# Created on: 13 дек. 2016 г.
33
# Author: sergey.fedorov
44

5-
if (NOT GBENCH_FOUND)
6-
find_package(GBenchmark REQUIRED)
7-
endif()
5+
find_package(ExternalProjectGBench REQUIRED)
86
if (NOT CMAKE_THREAD_LIBS_INIT)
97
find_package(Threads REQUIRED)
108
endif()

benchmark/matrix_benchmarks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Author: zmij
66
*/
77

8-
#include <benchmark/benchmark_api.h>
8+
#include <benchmark/benchmark.h>
99
#include <pushkin/math/vector.hpp>
1010
#include <pushkin/math/matrix.hpp>
1111

benchmark/vector_benchmarks.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Author: sergey.fedorov
66
*/
77

8-
#include <benchmark/benchmark_api.h>
8+
#include <benchmark/benchmark.h>
99
#include <pushkin/math/vector.hpp>
1010
#include <pushkin/math/matrix.hpp>
1111

@@ -259,4 +259,4 @@ BENCHMARK_TEMPLATE(VectorNorm, vector<float, 10>);
259259
} /* namespace math */
260260
} /* namespace psst */
261261

262-
BENCHMARK_MAIN()
262+
BENCHMARK_MAIN();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#FindExternalProjectZmijModules.cmake
2+
# Created on: Dec 2, 2018
3+
# Author: ser-fedorov
4+
5+
if (TARGET libzmijcmake)
6+
return()
7+
endif()
8+
9+
find_program(GIT_EXECUTABLE git)
10+
11+
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/cmake-scripts)
12+
execute_process(COMMAND ${GIT_EXECUTABLE} pull
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake-scripts)
14+
else()
15+
execute_process(COMMAND ${GIT_EXECUTABLE} clone -b develop https://github.com/zmij/cmake-scripts.git cmake-scripts
16+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
17+
endif()
18+
19+
set(ZMIJ_CMAKE_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/cmake-scripts)
20+
add_library(libzmijcmake IMPORTED INTERFACE)
21+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ZMIJ_CMAKE_SCRIPTS}/modules")

cmake/modules/FindGBenchmark.cmake

-38
This file was deleted.

include/pushkin/math/detail/matrix_detail.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ template < typename RowIndexTuple, ::std::size_t ColCount, typename T, typename
2020
struct matrix_builder;
2121

2222
template < ::std::size_t ... RowIndexes, ::std::size_t CC, typename T, typename Axes >
23-
struct matrix_builder < indexes_tuple< RowIndexes ... >, CC, T, Axes > :
23+
struct matrix_builder < std::index_sequence< RowIndexes ... >, CC, T, Axes > :
2424
data_holder< RowIndexes, vector< T, CC, Axes > > ...,
2525
axes_names<Axes>::template type<sizeof ... (RowIndexes),
26-
matrix_builder< indexes_tuple<RowIndexes...>, CC, T, Axes >,
26+
matrix_builder< std::index_sequence<RowIndexes...>, CC, T, Axes >,
2727
vector<T, CC, Axes>> {
2828

29-
using row_index_tuple = detail::indexes_tuple< RowIndexes ... >;
29+
using row_index_tuple = std::index_sequence< RowIndexes ... >;
3030
using row_type = vector< T, CC, Axes >;
3131

32-
static constexpr ::std::size_t row_count = row_index_tuple::size;
32+
static constexpr ::std::size_t row_count = sizeof...(RowIndexes);
3333
static constexpr ::std::size_t col_count = row_type::size;
3434
static constexpr ::std::size_t size = row_count * col_count;
3535

3636
using this_type = matrix_builder < row_index_tuple, CC, T, Axes >;
3737

38-
using col_index_tuple = typename detail::index_builder< CC >::type;
39-
using transposed_type = matrix_builder< col_index_tuple, row_index_tuple::size, T, Axes >;
38+
using col_index_tuple = std::make_index_sequence< CC >;
39+
using transposed_type = matrix_builder< col_index_tuple, row_count, T, Axes >;
4040

4141

4242
using row_iterator = row_type*;

include/pushkin/math/detail/vector_detail.hpp

+9-26
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
#define PUSHKIN_VECTOR_DETAIL_HPP_
1010

1111
#include <type_traits>
12+
#include <utility>
13+
1214
#include <pushkin/math/detail/axis_names.hpp>
1315
#include <pushkin/math/detail/value_traits.hpp>
1416

1517
namespace psst {
1618
namespace math {
1719

1820
namespace detail {
19-
/** Variadic template arguments unwrapping */
2021

22+
/** Variadic template arguments unwrapping */
2123
template< ::std::size_t Index, typename T >
2224
struct data_holder {
2325
static constexpr ::std::size_t index = Index;
@@ -60,34 +62,15 @@ struct data_holder {
6062
}
6163
};
6264

63-
template< ::std::size_t ... Indexes >
64-
struct indexes_tuple {
65-
static constexpr ::std::size_t size = sizeof ... (Indexes);
66-
};
67-
68-
template< ::std::size_t num, typename tp = indexes_tuple< > >
69-
struct index_builder;
70-
71-
template< ::std::size_t num, size_t ... Indexes >
72-
struct index_builder< num, indexes_tuple< Indexes ... > > : index_builder<
73-
num - 1, indexes_tuple< Indexes ..., sizeof ... (Indexes) > > {
74-
};
75-
76-
template< ::std::size_t ... Indexes >
77-
struct index_builder< 0, indexes_tuple< Indexes ... > > {
78-
using type = indexes_tuple< Indexes ... >;
79-
static constexpr ::std::size_t size = sizeof ... (Indexes);
80-
};
81-
8265
template < typename IndexTuple, typename T >
8366
struct vector_builder;
8467

8568
template < ::std::size_t ... Indexes, typename T >
86-
struct vector_builder< indexes_tuple< Indexes ... >, T > :
69+
struct vector_builder< std::index_sequence< Indexes ... >, T > :
8770
data_holder< Indexes, T > ... {
8871

8972
static constexpr ::std::size_t size = sizeof ... (Indexes);
90-
using indexes_tuple_type = indexes_tuple< Indexes ... >;
73+
using indexes_tuple_type = std::index_sequence< Indexes ... >;
9174
using this_type = vector_builder< indexes_tuple_type, T >;
9275

9376
using element_type = T;
@@ -120,7 +103,7 @@ struct vector_builder< indexes_tuple< Indexes ... >, T > :
120103
*/
121104
template < size_t ... IndexesR, typename U >
122105
vector_builder(
123-
vector_builder< indexes_tuple< IndexesR ... >, U > const& rhs,
106+
vector_builder< std::index_sequence< IndexesR ... >, U > const& rhs,
124107
typename ::std::enable_if< size <= sizeof ... (IndexesR) >::type* = 0 )
125108
: data_holder< Indexes, T >( rhs.template at< Indexes >() ) ... {}
126109

@@ -187,7 +170,7 @@ struct vector_builder< indexes_tuple< Indexes ... >, T > :
187170
iterator
188171
end()
189172
{
190-
return begin() + indexes_tuple_type::size;
173+
return begin() + size;
191174
}
192175

193176
const_iterator
@@ -198,13 +181,13 @@ struct vector_builder< indexes_tuple< Indexes ... >, T > :
198181
const_iterator
199182
cend() const
200183
{
201-
return begin() + indexes_tuple_type::size;
184+
return begin() + size;
202185
}
203186

204187
lvalue_reference
205188
operator[](size_t idx)
206189
{
207-
assert(idx < indexes_tuple_type::size);
190+
assert(idx < size);
208191
return begin()[idx];
209192
}
210193

include/pushkin/math/matrix.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace math {
2020
* @tparam CC column count;
2121
*/
2222
template < typename T, ::std::size_t RC, ::std::size_t CC, typename Axes >
23-
struct matrix : detail::matrix_builder< typename detail::index_builder< RC >::type, CC, T, Axes > {
23+
struct matrix : detail::matrix_builder< std::make_index_sequence< RC >, CC, T, Axes > {
2424

2525
using base_type = detail::matrix_builder<
26-
typename detail::index_builder< RC >::type, CC, T, Axes >;
26+
std::make_index_sequence< RC >, CC, T, Axes >;
2727

2828
using this_type = matrix< T, RC, CC, Axes >;
2929
using transposed_type = matrix< T, CC, RC, Axes >;

include/pushkin/math/vector.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ namespace math {
2424
template < typename T, size_t Size, typename Axes >
2525
struct vector
2626
: detail::vector_builder<
27-
typename detail::index_builder< Size >::type, T >,
27+
std::make_index_sequence< Size >, T >,
2828
detail::calculus_selector<T, Size, Axes>,
2929
detail::axes_names<Axes>::template type<Size, vector<T, Size, Axes>, T> {
3030

3131
using base_type = detail::vector_builder<
32-
typename detail::index_builder< Size >::type, T >;
32+
std::make_index_sequence< Size >, T >;
3333
using this_type = vector< T, Size, Axes >;
3434

3535
using value_traits = typename base_type::value_traits;

test/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
cmake_minimum_required(VERSION 2.6)
77

8-
if (NOT GTEST_INCLUDE_DIRS)
9-
find_package(GTest REQUIRED)
10-
endif()
8+
find_package(ExternalProjectGTest REQUIRED)
119
if (NOT CMAKE_THREAD_LIBS_INIT)
1210
find_package(Threads REQUIRED)
1311
endif()

0 commit comments

Comments
 (0)