Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Updates to support Visual Studio 14 (2015) D14REL.  This includes a workaround for what appears to be a regression in initializer list construction, as well as for an issue with template arithmetic during template overload resolution.

- Bumped the version to 2.0.1.
  • Loading branch information
demianmnave committed Oct 27, 2015
1 parent 85ceb3a commit 92aa0a4
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 18 deletions.
31 changes: 21 additions & 10 deletions cml/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,43 @@
/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

/* Macro for defaulted move: */
# define __CML_DEFAULT_MOVE = default


#elif defined(_MSC_VER)
/* VC++ support for C++11 features used by CML that may not be available to
* ther compilers:
*/

# if _MSC_VER < 1900
/* VC++ (at least VS12) does not support move from *this, so no need to
* disambiguate:
*/
#define __CML_REF

/* VC++ (at least VS12) does not support default move constructors: */
# define __CML_DEFAULT_MOVE
# define __CML_REF

/* VC++ (at least VS12) has brain-dead operator= overload resolution: */
# define CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS
# define CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS

# else

/* N2439 move semantics for *this, used, for example, to efficiently return
* an expression node from a class method. Without this, a temporary is
* returned instead:
*/
# define CML_HAS_RVALUE_REFERENCE_FROM_THIS

/* Trailing method type for ref from *this (to disambiguate overloads using
* rvalue reference from this):
*/
# define __CML_REF &

/* Defaulted move constructor supported: */
# define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR

# endif

#else
#warning "Unrecognized compiler; using safe defaults"

/* Assume no default move constructors: */
// # define CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR
// # define __CML_DEFAULT_MOVE

/* Assume no rvalue reference from this: */
// # define CML_HAS_RVALUE_REFERENCE_FROM_THIS
Expand Down
28 changes: 28 additions & 0 deletions cml/common/mpl/plus_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* -*- C++ -*- ------------------------------------------------------------
@@COPYRIGHT@@
*-----------------------------------------------------------------------*/
/** @file
*/

#pragma once

#ifndef cml_common_mpl_plus_c_h
#define cml_common_mpl_plus_c_h

namespace cml {

/** Helper to add two integral constants.
*
* @note This also avoids spurious VC14 "integral constant overflow"
* warnings.
*/
template<int a, int b> struct plus_c {
static const int value = a + b;
};

} // namespace cml

#endif

// -------------------------------------------------------------------------
// vim:ft=cpp:sw=2
10 changes: 10 additions & 0 deletions cml/mathlib/matrix/translation.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ matrix_get_translation_2D(const readable_matrix<Sub>& m)
-> n_basis_vector_of_t<Sub,2>
{
cml::check_affine_2D(m);
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
return n_basis_vector_of_t<Sub,2>(
m.basis_element(2,0), m.basis_element(2,1));
#else
return { m.basis_element(2,0), m.basis_element(2,1) };
#endif
}


Expand Down Expand Up @@ -165,7 +170,12 @@ matrix_get_translation(const readable_matrix<Sub>& m)
-> n_basis_vector_of_t<Sub,3>
{
cml::check_affine_3D(m);
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
return n_basis_vector_of_t<Sub,3>(
m.basis_element(3,0), m.basis_element(3,1), m.basis_element(3,2));
#else
return { m.basis_element(3,0), m.basis_element(3,1), m.basis_element(3,2) };
#endif
}


Expand Down
4 changes: 4 additions & 0 deletions cml/mathlib/vector/misc.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ template<class Sub> inline auto
perp(const readable_vector<Sub>& v) -> temporary_of_t<Sub>
{
cml::check_size(v, cml::int_c<2>());
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
return temporary_of_t<Sub>(- v[1], v[0]);
#else
return { - v[1], v[0] };
#endif
}

template<class Sub1, class Sub2> inline auto
Expand Down
2 changes: 1 addition & 1 deletion cml/matrix/writable_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class writable_matrix
* sizes are checked at compile time otherwise.
*/
template<class Sub> DerivedT&
set_col(int j, const readable_vector<Sub>& v);
set_col(int j, const readable_vector<Sub>& v) __CML_REF;

#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS
/** Copy @c v to column @c j of a temporary matrix.
Expand Down
2 changes: 1 addition & 1 deletion cml/matrix/writable_matrix.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ writable_matrix<DT>::set_row(int i, const readable_vector<Sub>& v) &&
#endif

template<class DT> template<class Sub> DT&
writable_matrix<DT>::set_col(int j, const readable_vector<Sub>& v)
writable_matrix<DT>::set_col(int j, const readable_vector<Sub>& v) __CML_REF
{
cml::check_same_row_size(*this, v);
for(int i = 0; i < this->rows(); ++ i) this->put(i,j, v.get(i));
Expand Down
23 changes: 23 additions & 0 deletions cml/vector/detail/check_or_resize.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ check_or_resize(writable_vector<Sub>& sub, int N)
}


/* check_or_resize for a read-only vector, left, that just forwards to
* check_same_size.
*/
template<class Sub, class Other> inline void
check_or_resize(
const readable_vector<Sub>& left, const readable_vector<Other>& right
)
{
cml::check_same_size(left, right);
}

/* check_or_resize for a resizable vector, left, that resizes the vector to
* ensure it has the same size as right.
*/
template<class Sub, class Other> inline auto
check_or_resize(
writable_vector<Sub>& left, const readable_vector<Other>& right
)
-> decltype(left.actual().resize(0), void())
{
left.actual().resize(cml::array_size_of(right));
}

/* check_or_resize for a read-only vector that verifies the size is
* other.size() + sizeof(eN):
*/
Expand Down
27 changes: 23 additions & 4 deletions cml/vector/detail/combined_size_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,38 @@
#ifndef cml_vector_detail_combined_size_of_h
#define cml_vector_detail_combined_size_of_h

#include <cml/common/mpl/plus_c.h>

namespace cml {
namespace detail {

template<class Sub, class... Elements> enable_if_fixed_size_t<Sub,
cml::int_c<array_size_of_c<Sub>::value + int(sizeof...(Elements))>
template<class Sub> inline
enable_if_fixed_size_t<Sub, cml::int_c<array_size_of_c<Sub>::value>>
combined_size_of(const readable_vector<Sub>&)
{
return array_size_of_c<Sub>::value;
}

template<class Sub, class... Elements> inline
enable_if_fixed_size_t<
Sub, cml::int_c<
cml::plus_c<array_size_of_c<Sub>::value,int(sizeof...(Elements))>::value
>
>
combined_size_of(const readable_vector<Sub>&, const Elements&...)
{
return cml::int_c<array_size_of_c<Sub>::value + int(sizeof...(Elements))>();
}

template<class Sub, class... Elements>
enable_if_dynamic_size_t<Sub, int>
template<class Sub> inline
enable_if_dynamic_size_t<Sub, int>
combined_size_of(const readable_vector<Sub>& sub)
{
return sub.size();
}

template<class Sub, class... Elements> inline
enable_if_dynamic_size_t<Sub, int>
combined_size_of(const readable_vector<Sub>& sub, const Elements&...)
{
return sub.size() + int(sizeof...(Elements));
Expand Down
4 changes: 2 additions & 2 deletions cml/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#define cml_version_h

/* Current CML version: */
#define CML_VERSION 200000U
#define CML_VERSION 200001U

/* Current CML version as a string: */
#define CML_VERSION_STRING "2.0.0"
#define CML_VERSION_STRING "2.0.1"

#endif

Expand Down

0 comments on commit 92aa0a4

Please sign in to comment.