Added constexpr to constructors and copy constructors.

This commit is contained in:
John Wellbelove 2019-02-10 10:54:54 +00:00
parent cf9ec9763e
commit 92d5aab61b
5 changed files with 32 additions and 31 deletions

View File

@ -66,19 +66,11 @@ class Timer
{
public:
Timer(int interruptId)
: callback(*this)
{
GetInterruptVectorsInstance().register_callback(interruptId, callback);
}
// Handler for interrupts from the timer.
void InterruptHandler(const size_t id)
{
std::cout << "Timer interrupt (member) : ID " << id << "\n";
}
etl::function_mp<Timer, size_t, &Timer::InterruptHandler> callback;
};
//********************************
@ -121,10 +113,14 @@ void UnhandledInterrupt(const size_t id)
}
// Declare the driver instances.
Timer timer(TIM1_CC_IRQ_HANDLER);
Timer timer;
Uart uart1(0, USART1_IRQ_HANDLER);
Uart uart2(1, USART2_IRQ_HANDLER);
// Declare a global callback for the timer.
// Uses the most efficient callback type for a class, as everthing is known at compile time.
etl::function_imp<Timer, size_t, timer, &Timer::InterruptHandler> timer_member_callback;
// Declare the callbacks for the free functions.
etl::function_fp<size_t, FreeTimerInterruptHandler> timer_free_callback;
etl::function_fp<size_t, UnhandledInterrupt> unhandled_callback;
@ -137,6 +133,7 @@ int main()
// Setup the callbacks.
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
interruptVectors.register_callback<TIM1_CC_IRQ_HANDLER>(timer_member_callback);
interruptVectors.register_callback<TIM2_IRQ_HANDLER>(timer_free_callback);
interruptVectors.register_unhandled_callback(unhandled_callback);

View File

@ -114,7 +114,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
array_view()
ETL_CONSTEXPR array_view()
: mbegin(nullptr),
mend(nullptr)
{
@ -125,7 +125,7 @@ namespace etl
/// data() and size() member functions.
//*************************************************************************
template <typename TArray>
explicit array_view(TArray& a)
ETL_CONSTEXPR explicit array_view(TArray& a)
: mbegin(a.data()),
mend(a.data() + a.size())
{
@ -135,7 +135,7 @@ namespace etl
/// Construct from iterators
//*************************************************************************
template <typename TIterator>
array_view(TIterator begin_, TIterator end_)
ETL_CONSTEXPR array_view(TIterator begin_, TIterator end_)
: mbegin(etl::addressof(*begin_)),
mend(etl::addressof(*begin_) + std::distance(begin_, end_))
{
@ -146,7 +146,7 @@ namespace etl
//*************************************************************************
template <typename TIterator,
typename TSize>
array_view(TIterator begin_, TSize size_)
ETL_CONSTEXPR array_view(TIterator begin_, TSize size_)
: mbegin(etl::addressof(*begin_)),
mend(etl::addressof(*begin_) + size_)
{
@ -156,7 +156,7 @@ namespace etl
/// Construct from C array
//*************************************************************************
template<const size_t ARRAY_SIZE>
explicit array_view(T(&begin_)[ARRAY_SIZE])
ETL_CONSTEXPR explicit array_view(T(&begin_)[ARRAY_SIZE])
: mbegin(begin_),
mend(begin_ + ARRAY_SIZE)
{
@ -165,7 +165,7 @@ namespace etl
//*************************************************************************
/// Copy constructor
//*************************************************************************
array_view(const array_view& other)
ETL_CONSTEXPR array_view(const array_view& other)
: mbegin(other.mbegin),
mend(other.mend)
{
@ -504,7 +504,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
const_array_view()
ETL_CONSTEXPR const_array_view()
: mbegin(nullptr),
mend(nullptr)
{
@ -515,7 +515,7 @@ namespace etl
/// data() and size() member functions.
//*************************************************************************
template <typename TArray>
explicit const_array_view(TArray& a)
ETL_CONSTEXPR explicit const_array_view(TArray& a)
: mbegin(a.data()),
mend(a.data() + a.size())
{
@ -525,7 +525,7 @@ namespace etl
/// Construct from iterators
//*************************************************************************
template <typename TIterator>
const_array_view(TIterator begin_, TIterator end_)
ETL_CONSTEXPR const_array_view(TIterator begin_, TIterator end_)
: mbegin(etl::addressof(*begin_)),
mend(etl::addressof(*begin_) + std::distance(begin_, end_))
{
@ -536,7 +536,7 @@ namespace etl
//*************************************************************************
template <typename TIterator,
typename TSize>
const_array_view(TIterator begin_, TSize size_)
ETL_CONSTEXPR const_array_view(TIterator begin_, TSize size_)
: mbegin(etl::addressof(*begin_)),
mend(etl::addressof(*begin_) + size_)
{
@ -546,16 +546,16 @@ namespace etl
/// Construct from C array
//*************************************************************************
template<const size_t ARRAY_SIZE>
explicit const_array_view(const T(&begin_)[ARRAY_SIZE])
ETL_CONSTEXPR explicit const_array_view(const T(&begin_)[ARRAY_SIZE])
: mbegin(begin_),
mend(begin_ + ARRAY_SIZE)
{
}
//*************************************************************************
//************0*************************************************************
/// Copy constructor
//*************************************************************************
const_array_view(const array_view<T>& other)
ETL_CONSTEXPR const_array_view(const array_view<T>& other)
: mbegin(other.begin()),
mend(other.end())
{
@ -564,9 +564,9 @@ namespace etl
//*************************************************************************
/// Copy constructor
//*************************************************************************
const_array_view(const const_array_view& other)
ETL_CONSTEXPR const_array_view(const const_array_view& other)
: mbegin(other.mbegin),
mend(other.mend)
mend(other.mend)
{
}

View File

@ -118,7 +118,7 @@ namespace etl
//*************************************************************************
/// Default constructor.
//*************************************************************************
basic_string_view()
ETL_CONSTEXPR basic_string_view()
: mbegin(nullptr),
mend(nullptr)
{
@ -127,7 +127,7 @@ namespace etl
//*************************************************************************
/// Construct from T*.
//*************************************************************************
basic_string_view(const T* begin_)
ETL_CONSTEXPR basic_string_view(const T* begin_)
: mbegin(begin_),
mend(begin_ + TTraits::length(begin_))
{
@ -136,7 +136,7 @@ namespace etl
//*************************************************************************
/// Construct from pointer range.
//*************************************************************************
basic_string_view(const T* begin_, const T* end_)
ETL_CONSTEXPR basic_string_view(const T* begin_, const T* end_)
: mbegin(begin_),
mend(end_)
{
@ -146,7 +146,7 @@ namespace etl
/// Construct from iterator/size.
//*************************************************************************
template <typename TSize, typename TDummy = typename etl::enable_if<etl::is_integral<TSize>::value, void>::type>
basic_string_view(const T* begin_, TSize size_)
ETL_CONSTEXPR basic_string_view(const T* begin_, TSize size_)
: mbegin(begin_),
mend(begin_ + size_)
{
@ -155,7 +155,7 @@ namespace etl
//*************************************************************************
/// Copy constructor
//*************************************************************************
basic_string_view(const basic_string_view& other)
ETL_CONSTEXPR basic_string_view(const basic_string_view& other)
: mbegin(other.mbegin),
mend(other.mend)
{

View File

@ -38,8 +38,8 @@ SOFTWARE.
///\ingroup utilities
#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 8
#define ETL_VERSION_PATCH 2
#define ETL_VERSION_MINOR 9
#define ETL_VERSION_PATCH 0
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))

View File

@ -1,3 +1,7 @@
===============================================================================
14.9.0
Added constexpr constructors to string_view and array_view.
===============================================================================
14.8.2
Added missing #include "stl/interator.h" in frame_check_sequence.h