Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Templates: Stop inferring const unnecessarily
Browse files Browse the repository at this point in the history
In some configurations, clang complains when changing the key in
groupBy, because the key's type is, for example in this case:
"const Segment"

This doesn't actually const_cast anything, it just changes the
signature of the generated GroupBy code.
  • Loading branch information
mrcslws committed Aug 23, 2016
1 parent ffc20bd commit 36c9d1e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/nupic/algorithms/Connections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ namespace nupic
CellIdx cell;

Segment(SegmentIdx idx, CellIdx cell) : idx(idx), cell(cell) {}
Segment(const Segment& s) : idx(s.idx), cell(s.cell) {}
Segment() {}

bool operator==(const Segment &other) const;
Expand Down
63 changes: 36 additions & 27 deletions src/nupic/utils/GroupBy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ namespace nupic

template<typename Iterator0, typename KeyFn0,
typename Element0 = decltype(*std::declval<Iterator0>()),
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
class GroupBy1
{
public:
Expand Down Expand Up @@ -189,9 +190,10 @@ namespace nupic
// ==========================================================================

template<typename Iterator0, typename KeyFn0,
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
static KeyType minFrontKey(KeyType frontrunner,
Iterator0 begin0, Iterator0 end0, KeyFn0 keyFn0)
{
Expand All @@ -209,9 +211,10 @@ namespace nupic
typename Iterator1, typename KeyFn1,
typename Element0 = decltype(*std::declval<Iterator0>()),
typename Element1 = decltype(*std::declval<Iterator1>()),
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
class GroupBy2
{
public:
Expand Down Expand Up @@ -376,9 +379,10 @@ namespace nupic

template<typename Iterator0, typename KeyFn0,
typename Iterator1, typename KeyFn1,
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
static KeyType minFrontKey(KeyType frontrunner,
Iterator0 begin0, Iterator0 end0, KeyFn0 keyFn0,
Iterator1 begin1, Iterator1 end1, KeyFn1 keyFn1)
Expand All @@ -404,9 +408,10 @@ namespace nupic
typename Element0 = decltype(*std::declval<Iterator0>()),
typename Element1 = decltype(*std::declval<Iterator1>()),
typename Element2 = decltype(*std::declval<Iterator2>()),
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
class GroupBy3
{
public:
Expand Down Expand Up @@ -617,9 +622,10 @@ namespace nupic
template<typename Iterator0, typename KeyFn0,
typename Iterator1, typename KeyFn1,
typename Iterator2, typename KeyFn2,
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
static KeyType minFrontKey(KeyType frontrunner,
Iterator0 begin0, Iterator0 end0, KeyFn0 keyFn0,
Iterator1 begin1, Iterator1 end1, KeyFn1 keyFn1,
Expand Down Expand Up @@ -653,9 +659,10 @@ namespace nupic
typename Element1 = decltype(*std::declval<Iterator1>()),
typename Element2 = decltype(*std::declval<Iterator2>()),
typename Element3 = decltype(*std::declval<Iterator3>()),
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
class GroupBy4
{
public:
Expand Down Expand Up @@ -912,9 +919,10 @@ namespace nupic
typename Iterator1, typename KeyFn1,
typename Iterator2, typename KeyFn2,
typename Iterator3, typename KeyFn3,
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
static KeyType minFrontKey(KeyType frontrunner,
Iterator0 begin0, Iterator0 end0, KeyFn0 keyFn0,
Iterator1 begin1, Iterator1 end1, KeyFn1 keyFn1,
Expand Down Expand Up @@ -956,9 +964,10 @@ namespace nupic
typename Element2 = decltype(*std::declval<Iterator2>()),
typename Element3 = decltype(*std::declval<Iterator3>()),
typename Element4 = decltype(*std::declval<Iterator4>()),
typename KeyType = typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type>
typename KeyType = typename std::remove_const<
typename std::result_of<
KeyFn0(decltype(*std::declval<Iterator0>()))
>::type >::type>
class GroupBy5
{
public:
Expand Down

0 comments on commit 36c9d1e

Please sign in to comment.