Skip to content

Commit

Permalink
Merge pull request #765 from nlohmann/feature/issue698
Browse files Browse the repository at this point in the history
using more CMake
  • Loading branch information
nlohmann authored Oct 4, 2017
2 parents 7435d54 + e2045ea commit 4e81c1d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 113 deletions.
60 changes: 25 additions & 35 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,28 @@ matrix:
include:

# Valgrind

- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=valgrind
- CMAKE_OPTIONS=-DJSON_Valgrind=ON
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, valgrind]
after_success:
- make check TEST_PREFIX="valgrind --error-exitcode=1 --leak-check=full " TEST_PATTERN=""
packages: ['g++-4.9', 'valgrind', 'ninja-build']

# clang sanitizer
- os: linux
compiler: clang
env:
- COMPILER=clang++-5.0
- SPECIAL=sanitizer
- CMAKE_OPTIONS=-DJSON_Sanitizer=ON
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0']
after_success:
- make clang_sanitize -j4
packages: ['g++-6', 'clang-5.0', 'ninja-build']

# cppcheck

- os: linux
compiler: gcc
env:
Expand All @@ -65,24 +59,20 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, cppcheck]
packages: ['g++-4.9', 'cppcheck', 'ninja-build']
after_success:
- make cppcheck

# no exceptions

- os: linux
compiler: gcc
env:
- COMPILER=g++-4.9
- SPECIAL=no_exceptions
- CMAKE_OPTIONS=-DJSON_NoExceptions=ON
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [g++-4.9, cppcheck]
after_success:
- make clean
- CPPFLAGS="-DJSON_NOEXCEPTION" make check TEST_PATTERN="-e \"*\""
packages: ['g++-4.9', 'ninja-build']

# Coveralls (http://gronlier.fr/blog/2015/01/adding-code-coverage-to-your-c-project/)

Expand All @@ -91,7 +81,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-4.9', 'ruby']
packages: ['g++-4.9', 'ruby', 'ninja-build']
before_script:
- wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz
- tar xf lcov_1.11.orig.tar.gz
Expand Down Expand Up @@ -119,7 +109,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: ['g++-6', 'clang-3.6']
packages: ['g++-6', 'clang-3.6', 'ninja-build']
coverity_scan:
project:
name: "nlohmann/json"
Expand Down Expand Up @@ -163,31 +153,31 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-4.9
packages: ['g++-4.9', 'ninja-build']

- os: linux
compiler: gcc
env: COMPILER=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-5
packages: ['g++-5', 'ninja-build']

- os: linux
compiler: gcc
env: COMPILER=g++-6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-6
packages: ['g++-6', 'ninja-build']

- os: linux
compiler: gcc
env: COMPILER=g++-7
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-7
packages: ['g++-7', 'ninja-build']

- os: linux
compiler: gcc
Expand All @@ -197,7 +187,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-7
packages: ['g++-7', 'ninja-build']

# Linux / Clang

Expand All @@ -207,55 +197,55 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
packages: ['g++-6', 'clang-3.5']
packages: ['g++-6', 'clang-3.5', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-3.6
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: ['g++-6', 'clang-3.6']
packages: ['g++-6', 'clang-3.6', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-3.7
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
packages: ['g++-6', 'clang-3.7']
packages: ['g++-6', 'clang-3.7', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-3.8
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'clang-3.8']
packages: ['g++-6', 'clang-3.8', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-3.9
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-6', 'clang-3.9']
packages: ['g++-6', 'clang-3.9', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-4.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['g++-6', 'clang-4.0']
packages: ['g++-6', 'clang-4.0', 'ninja-build']

- os: linux
compiler: clang
env: COMPILER=clang++-5.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0']
packages: ['g++-6', 'clang-5.0', 'ninja-build']

- os: linux
compiler: clang
Expand All @@ -265,7 +255,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0']
packages: ['g++-6', 'clang-5.0', 'ninja-build']

################
# build script #
Expand All @@ -274,9 +264,9 @@ matrix:
script:
# get CMake (only for systems with brew - macOS)
- |
if [[ !(-x $(which cmake)) && (-x $(which brew)) ]]; then
if [[ (-x $(which brew)) ]]; then
brew update
brew install cmake
brew install cmake ninja
cmake --version
fi
Expand All @@ -289,7 +279,7 @@ script:

# compile and execute unit tests
- mkdir -p build && cd build
- cmake .. && cmake --build . --config Release -- -j4
- cmake .. ${CMAKE_OPTIONS} -GNinja && cmake --build . --config Release
- ctest -C Release -V
- cd ..

Expand Down
10 changes: 3 additions & 7 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,11 +745,10 @@ struct external_constructor<value_t::array>
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
static void construct(BasicJsonType& j, const std::valarray<T>& arr)
{
using std::begin;
using std::end;
j.m_type = value_t::array;
j.m_value = value_t::array;
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.m_value.array->resize(arr.size());
std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
j.assert_invariant();
}
};
Expand Down Expand Up @@ -1190,10 +1189,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name())));
}
l.resize(j.size());
for (size_t i = 0; i < j.size(); ++i)
{
l[i] = j[i];
}
std::copy(j.m_value.array->begin(), j.m_value.array->end(), std::begin(l));
}

template<typename BasicJsonType, typename CompatibleArrayType>
Expand Down
Loading

0 comments on commit 4e81c1d

Please sign in to comment.