.. _val-getting-started: Getting started =============== Native example -------------- Create a typed VAL value and format it through the polymorphic interface: .. code-block:: cpp #include #include #include #include #include int main() { std::vector data = {1.0, 2.0, 3.0, 4.0}; auto matrix = std::make_unique( data, snt::val::Array::ShapeType{2, 2} ); std::cout << matrix->to_string() << "\n"; std::cout << snt::val::to_string(matrix->get_shape()) << "\n"; return 0; } The value owns its flattened data and stores the shape separately. The convenience type ``ArrayValueFloat64`` is a typed ``ArrayValue`` with the public ``DataType::Float64`` tag. Build and run ------------- Install the C++ package using :doc:`../../installation` with the ``VAL`` module enabled. Save the example above as ``main.cpp`` and create this ``CMakeLists.txt`` in the same directory: .. code-block:: cmake cmake_minimum_required(VERSION 3.22) project(snt_val_example LANGUAGES C CXX) find_package(snt CONFIG REQUIRED) add_executable(application main.cpp) target_compile_features(application PRIVATE cxx_std_17) target_link_libraries(application PRIVATE snt-val) Configure with the installed package prefix, build, and run: .. code-block:: console cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/snt cmake --build build ./build/application Expected output: .. code-block:: text [[1, 2], [3, 4]] [2,2] Replace ``/path/to/snt`` with the installation prefix; omit that option if CMake already finds SNT. C is enabled for discovery of HDF5 in packages built with DIP support. See :ref:`cmake-consumer` for package discovery details. Continue with :doc:`Workflows ` for arithmetic and conversion. The generated declarations are in the :doc:`C++ API reference <../../api/cpp_val>`.