Skip to content

Commit

Permalink
Merge branch 'master' into 3.05.03
Browse files Browse the repository at this point in the history
  • Loading branch information
rparolin committed Mar 15, 2017
2 parents c151dc8 + 6218bb7 commit 1502123
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ install:

before_script:
- if [[ -n "$USE_CLANG_39" ]]; then export PATH="${CLANG_39_PATH}/bin:$PATH" ;fi
- if [[ -n "$USE_CLANG_39" ]]; then export CC="clang"; fi
- if [[ -n "$USE_CLANG_39" ]]; then export CXX="clang++"; fi
- if [[ -n "$USE_CLANG_39" ]]; then export CC="clang" ;fi
- if [[ -n "$USE_CLANG_39" ]]; then export CXX="clang++" ;fi
- if [[ -n "$USE_CLANG_39" ]]; then export CXXFLAGS="$CXXFLAGS -I${CLANG_39_PATH}/include -std=c++11 -stdlib=libc++" ;fi
- if [[ -n "$USE_CLANG_39" ]]; then export LDFLAGS="$LDFLAGS -L${CLANG_39_PATH}/lib" ;fi
- mkdir build_$EASTL_CONFIG
Expand All @@ -62,7 +62,7 @@ before_script:
script:
# Run Tests
- cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/test
- ctest -C $EASTL_CONFIG -V
- ctest -C $EASTL_CONFIG -V || exit 1
# Run Benchmarks
- cd $TRAVIS_BUILD_DIR/build_$EASTL_CONFIG/benchmark
- ctest -C $EASTL_CONFIG -V
- ctest -C $EASTL_CONFIG -V || exit 1
38 changes: 38 additions & 0 deletions include/EASTL/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ namespace eastl
T& operator[](Key&& key);
#endif

T& at(const Key& key);
const T& at(const Key& key) const;

}; // map


Expand Down Expand Up @@ -439,6 +442,41 @@ namespace eastl
#endif


template <typename Key, typename T, typename Compare, typename Allocator>
inline T& map<Key, T, Compare, Allocator>::at(const Key& key)
{
iterator itLower(lower_bound(key)); // itLower->first is >= key.

if(itLower == end())
{
#if EASTL_EXCEPTIONS_ENABLED
throw std::out_of_range("map::at key does not exist");
#else
EASTL_FAIL_MSG("map::at key does not exist");
#endif
}

return (*itLower).second;
}


template <typename Key, typename T, typename Compare, typename Allocator>
inline const T& map<Key, T, Compare, Allocator>::at(const Key& key) const
{
const_iterator itLower(lower_bound(key)); // itLower->first is >= key.

if(itLower == end())
{
#if EASTL_EXCEPTIONS_ENABLED
throw std::out_of_range("map::at key does not exist");
#else
EASTL_FAIL_MSG("map::at key does not exist");
#endif
}

return (*itLower).second;
}




Expand Down
19 changes: 19 additions & 0 deletions test/packages/EATest/include/EATest/EATest.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,25 @@ namespace EA
#define EATEST_VERIFY_F(bExpression, pFormat, ...) EA::UnitTest::TestInternal::EATEST_VERIFY_F_IMP((bExpression), nErrorCount, __FILE__, __LINE__, pFormat, __VA_ARGS__)
#endif

/// EATEST_VERIFY_THROW
/// EATEST_VERIFY_NOTHROW
///
/// This macro confirms whether or not an expression throws or doesn't throw. If it's not the case that EASTL_EXCEPTIONS_ENABLED
/// the provided expression will not be evaluated.
///
/// See EATEST_VERIFY for details about error reporting and the _MSG variants
#if EASTL_EXCEPTIONS_ENABLED
#define EATEST_VERIFY_THROW(expression) {bool isNoThrow; try{ {expression;} isNoThrow=true; }catch(...){isNoThrow=false;} EATEST_VERIFY(!isNoThrow); }
#define EATEST_VERIFY_NOTHROW(expression) {bool isNoThrow; try{ {expression;} isNoThrow=true; }catch(...){isNoThrow=false;} EATEST_VERIFY(isNoThrow); }
#define EATEST_VERIFY_THROW_MSG(expression, msg) {bool isNoThrow; try{ {expression;} isNoThrow=true; }catch(...){isNoThrow=false;} EATEST_VERIFY_MSG(!isNoThrow, msg); }
#define EATEST_VERIFY_NOTHROW_MSG(expression, msg) {bool isNoThrow; try{ {expression;} isNoThrow=true; }catch(...){isNoThrow=false;} EATEST_VERIFY_MSG(isNoThrow, msg); }
#else
#define EATEST_VERIFY_THROW(expression)
#define EATEST_VERIFY_NOTHROW(expression)
#define EATEST_VERIFY_THROW_MSG(expression, msg)
#define EATEST_VERIFY_NOTHROW_MSG(expression, msg)
#endif


///////////////////////////////////////////////////////////////////////
/// GetSystemTimeMicroseconds
Expand Down
24 changes: 23 additions & 1 deletion test/source/TestMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ int TestMap()
EATEST_VERIFY(m.empty());
}


{
// User reports that EASTL_VALIDATE_COMPARE_ENABLED / EASTL_COMPARE_VALIDATE isn't compiling for this case.
eastl::map<eastl::string8, int> m;
Expand All @@ -141,6 +140,29 @@ int TestMap()
EATEST_VERIFY(v.validate());
}

{
typedef eastl::map<int, int> IntIntMap;
IntIntMap map1;

#if EASTL_EXCEPTIONS_ENABLED
EATEST_VERIFY_THROW(map1.at(0));
#endif
map1[0]=1;
#if EASTL_EXCEPTIONS_ENABLED
EATEST_VERIFY_NOTHROW(map1.at(0));
#endif
EATEST_VERIFY(map1.at(0) == 1);

const IntIntMap map2;
const IntIntMap map3(map1);

#if EASTL_EXCEPTIONS_ENABLED
EATEST_VERIFY_THROW(map2.at(0));
EATEST_VERIFY_NOTHROW(map3.at(0));
#endif
EATEST_VERIFY(map3.at(0) == 1);
}

// todo: create a test case for this.
// {
// // User reports that an incorrectly wrapped pair key used to insert into an eastl map compiles when it should fire a compiler error about unconvertible types.
Expand Down

0 comments on commit 1502123

Please sign in to comment.