NlohmanJSON
NlohmanはC++をJavascriptにしてしまおうという企みです.
- 変数を宣言するのはバカである.なぜならば, 1.23 と言われて整数だと思う奴はいないからである. 'Aho'を見て倍精度だと思う奴がいないのと同じである.
- ばってんくさ,文字列'1'と文字列'2'を結合すると結果は, 文字列'12'であると思う人と,文字列'3'であると思う人が出現するとよ.
- そげな場合だけ,「数値だにゃ'1'」+ 「数値だにゃ'2'」と書けば良い.すると結果が'3'で確定する.こいでよかやろ
- で, 値と名前をセットにして{名前: 値}をJSONという. 値が文字列なのか数値なのか関数なのかは, 鳴かせて見て「があ」と言えばアヒル型である.というダック型で記述する.
- JSONは{名前:JSON, JSON,...}でもよい ...てこた{名前: {名前: JSON},1,function(),...} も可能な訳だが, これをC++で使えるようにするのがNlohmanJSONライブラリである.
- こいつ,新型の天才だな.なんで車屋(ベンツ)勤務なんだ. ベンツのくせいにAIとかしてるのかな
- 変数の型やサイズ,個数は,実行するまで確定しないところがミソ.いうたら名前も確定してないな・・・(いわゆる動的確保.走りながらプログラムが確定していくが終わるまで全体は定まらない)
- ま,あんた自身も,生まれた時に,どこで死ぬのか,確定してないしな.
V3.12.0のインストール
ここに置いてあるので(Darwinってのは金臭い「MacOS」「OSX」を口にしたくない人がMacOSと言いたい時に使う言葉)
$ sudo ./nlohmann_json-3.12.0-Darwin.sh --prefix=/usr/local
Password:おまえのパスワード
nlohmann_json Installer Version: 3.12.0, Copyright (c) Humanity
This is a self-extracting archive.
The archive will be extracted to: /usr/local
If you want to stop extracting, please press <ctrl-C>.
LICENSE
=======
This is an installer created using CPack (https://cmake.org). No license provided. じゃあ聞くなよ
Do you accept the license? [yn]: y
By default the nlohmann_json will be installed in:
"/usr/local/nlohmann_json-3.12.0-Darwin"
Do you want to include the subdirectory nlohmann_json-3.12.0-Darwin?
Saying no will install in: "/usr/local" [Yn]: n
Using target directory: /usr/local
Extracting, please wait...
Unpacking finished successfully
これで /usr/local/include/nlohman にインストールされる. たぶん pkgconfig や cmake も動くが使い方は各自努力せよ
以下は暇な人用のパッケージ作成方法です
V3.12.0のパッケージ作成
ん?これ前見た時にはヘッダーしかなかった記憶が?インストールってあるのかな
$ git clone https://github.com/nlohmann/json.git $ git checkout -b TEST refs/tags/v3.12.0 これで, V3.12.0 になるんだったよね $ mkdir build $ cd build $ cmake .. $ make ... [ 38%] Built target test-element_access2_cpp14 ←なんかテストみたいなのビルドしてるな ... $ make help The following are some of the valid targets for this Makefile: ... all (the default if no target is provided) ... clean ... depend ... codegen ... edit_cache ... install ... install/local ... install/strip ... list_install_components ... package ... package_source ... rebuild_cache ... test ... Continuous ... ContinuousBuild ... ContinuousConfigure ... $ make test Running tests... Test project /Users/sugimoto/Documents/Source/Free/arm64/json/build Start 1: download_test_data 1/101 Test #1: download_test_data ............................. Passed 13.78 sec Start 2: test-algorithms_cpp11 2/101 Test #2: test-algorithms_cpp11 .......................... Passed 0.76 sec ... 100% tests passed, 0 tests failed out of 101 $ make package
[ 99%] Built target abi_compat_diag
[100%] Built target abi_compat_inline_ns
Run CPack packaging tool...
CPack: Create package using STGZ
CPack: Install projects
CPack: - Run preinstall target for: nlohmann_json
CPack: - Install project: nlohmann_json []
CPack: Create package
CPack: - package: /Users/sugimoto/Documents/Source/Free/arm64/json/build/nlohmann_json-3.12.0-Darwin.sh generated.
CPack: Create package using TGZ
CPack: Install projects
CPack: - Run preinstall target for: nlohmann_json
CPack: - Install project: nlohmann_json []
CPack: Create package
CPack: - package: /Users/sugimoto/Documents/Source/Free/arm64/json/build/nlohmann_json-3.12.0-Darwin.tar.gz generated.
どうなってんだこれ. 天災の考えることはわからんぞ. だが, nlohmann_json-3.12.0-Darwin.shってのと, nlohmann_json-3.12.0-Darwin.tar.gz ってのができた.おそらくパッケージ自身はtgzのほうで, アンパックするスクリプトがついてんのがshの方だな. 面白そうだから,実行してみよう!
$ tar ztf nlohmann_json-3.12.0-Darwin.tar.gz ← 言いつつ実行せずに中身をのぞいて見た
nlohmann_json-3.12.0-Darwin/include/
nlohmann_json-3.12.0-Darwin/include/nlohmann/
nlohmann_json-3.12.0-Darwin/include/nlohmann/ordered_map.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/json.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/adl_serializer.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/byte_container_with_subtype.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/hash.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/string_escape.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/json_custom_base_class.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/json_ref.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/conversions/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/conversions/to_chars.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/conversions/from_json.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/conversions/to_json.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/value_t.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/position_t.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/parser.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/json_sax.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/binary_reader.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/input_adapters.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/input/lexer.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/string_concat.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/string_utils.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/macro_scope.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/output/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/output/output_adapters.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/output/serializer.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/output/binary_writer.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/is_sax.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/call_std/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/call_std/end.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/call_std/begin.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/identity_tag.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/type_traits.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/cpp_future.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/detected.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/void_t.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/meta/std_fs.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/json_pointer.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/exceptions.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/abi_macros.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/macro_unscope.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/iter_impl.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/json_reverse_iterator.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/iteration_proxy.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/iterator_traits.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/internal_iterator.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/detail/iterators/primitive_iterator.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/thirdparty/
nlohmann_json-3.12.0-Darwin/include/nlohmann/thirdparty/hedley/
nlohmann_json-3.12.0-Darwin/include/nlohmann/thirdparty/hedley/hedley.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/thirdparty/hedley/hedley_undef.hpp
nlohmann_json-3.12.0-Darwin/include/nlohmann/json_fwd.hpp
nlohmann_json-3.12.0-Darwin/share/
nlohmann_json-3.12.0-Darwin/share/pkgconfig/
nlohmann_json-3.12.0-Darwin/share/pkgconfig/nlohmann_json.pc
nlohmann_json-3.12.0-Darwin/share/cmake/
nlohmann_json-3.12.0-Darwin/share/cmake/nlohmann_json/
nlohmann_json-3.12.0-Darwin/share/cmake/nlohmann_json/nlohmann_jsonTargets.cmake
nlohmann_json-3.12.0-Darwin/share/cmake/nlohmann_json/nlohmann_jsonConfigVersion.cmake
nlohmann_json-3.12.0-Darwin/share/cmake/nlohmann_json/nlohmann_jsonConfig.cmake
ふむふむ./usr/local/include に入れるべきヘッダーファイル,/usr/local/share/pkgconfig にいれるべき
pkgconfig のパーツと. /usr/local/share/cmake に入れる cmake のパーツか.全部テキストファイルだな.
$ ./nlohmann_json-3.12.0-Darwin.sh --help
Usage: ./nlohmann_json-3.12.0-Darwin.sh [options]
Options: [defaults in brackets after descriptions]
--help print this message
--version print cmake installer version
--prefix=dir directory in which to install
--include-subdir include the nlohmann_json-3.12.0-Darwin subdirectory
--exclude-subdir exclude the nlohmann_json-3.12.0-Darwin subdirectory
--skip-license accept license
$ sudo ./nlohmann_json-3.12.0-Darwin.sh --prefix=/usr/local
Password:
nlohmann_json Installer Version: 3.12.0, Copyright (c) Humanity
This is a self-extracting archive.
The archive will be extracted to: /usr/local
If you want to stop extracting, please press <ctrl-C>.
LICENSE
=======
This is an installer created using CPack (https://cmake.org). No license provided.
Do you accept the license? [yn]:
y
By default the nlohmann_json will be installed in:
"/usr/local/nlohmann_json-3.12.0-Darwin"
Do you want to include the subdirectory nlohmann_json-3.12.0-Darwin?
Saying no will install in: "/usr/local" [Yn]:
n
Using target directory: /usr/local
Extracting, please wait...
Unpacking finished successfully
ほうほう. 便利やんけ.
V3.10.2のパッケージ作成(失敗)
VTKのビルド失敗原因は, nlohmanJSON V3.10.2を使っているというのが原因ではないのか.
$ git clone https://github.com/nlohmann/json.git
$ cd json
$ git checkout -b TEST refs/tags/v3.10.2 ← これで V3.10.2 になる
$ mkdir build
$ cd build
$ cmake ..
$ make
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk/usr/include/c++/v1/__memory/all
ocator_traits.h:378:17: error: static assertion failed due to requirement 'is_same<(anonymous namespace)::bad_allocator<nlohmann::
basic_json<std::map, std::vector, std::string, bool, long long, unsigned long long, double, (anonymous namespace)::bad_allocator,
nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>>>, std::allocator<nlohmann::basic_json<std::ma
p, std::vector, std::string, bool, long long, unsigned long long, double, (anonymous namespace)::bad_allocator, nlohmann::adl_seri
alizer, std::vector<unsigned char, std::allocator<unsigned char>>>>>::value': [allocator.requirements] states that rebinding an a
llocator to the same type should result in the original allocator
378 | static_assert(is_same<_Alloc, __rebind_alloc<_Traits, typename _Traits::value_type> >::value,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
おお,エラー大量に吐いて,ビルドできないのでした.VTKがビルドできないのこれだな!ザッカーバーグの手下どもはAppleのせいにしようとしているが,見当違いもいいとこだな(Reactの出来が悪いとは言ってねえよ)
File attachments
Attachment | Size |
---|---|
nlohmann_json-3.12.zip | 148.09 KB |