Created
September 4, 2014 14:15
-
-
Save plasma-effect/e08cda7dcf91ea2870e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright plasma-effect 2014. | |
// Distributed under the Boost Software License, Version 1.0. | |
//(See accompanying file LICENSE_1_0.txt or copy at | |
// http://www.boost.org/LICENSE_1_0.txt) | |
#pragma once | |
#include<vector> | |
#include<utility> | |
#include<algorithm> | |
#include<type_traits> | |
namespace plasma | |
{ | |
template<std::size_t... Is>struct index_tuple{}; | |
namespace detail | |
{ | |
template<std::size_t, class, bool>struct index_count_impl; | |
template<std::size_t N, std::size_t... Is> | |
struct index_count_impl < N, index_tuple<Is...>, true > | |
{ | |
typedef index_tuple<Is..., (Is + N)..., 2 * N> type; | |
}; | |
template<std::size_t N, std::size_t... Is> | |
struct index_count_impl < N, index_tuple<Is...>, false > | |
{ | |
typedef index_tuple<Is..., (Is + N)...> type; | |
}; | |
} | |
template<std::size_t N>struct index_count | |
{ | |
typedef typename detail::index_count_impl < | |
N / 2, typename index_count<N / 2>::type, N % 2 > ::type type; | |
}; | |
template<>struct index_count < 0 > | |
{ | |
typedef index_tuple<> type; | |
}; | |
template<std::size_t N>typename index_count<N>::type make_index_count() | |
{ | |
return typename index_count<N>::type(); | |
} | |
template<class>struct sfinae_helper | |
{ | |
typedef void type; | |
}; | |
template<class T>struct polynomial | |
{ | |
std::size_t deg_; | |
std::vector<T> coefficient_; | |
//default construct | |
polynomial() :deg_(0), coefficient_(){} | |
//iterator | |
template<class InputIterator> | |
polynomial(InputIterator beg, InputIterator end) | |
: deg_(std::distance(beg, end)-1), coefficient_(deg_+1) | |
{ | |
std::move(beg, end, coefficient_.begin()); | |
} | |
template<std::size_t N, std::size_t... Is> | |
polynomial(T const(&ar)[N], index_tuple<Is...>) | |
: deg_(N - 1), coefficient_({ ar[Is]... }){} | |
//array | |
template<std::size_t N> | |
polynomial(T const(&ar)[N]) | |
:polynomial(ar, make_index_count<N>()){} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment