/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Application Test-FixedList Description Simple tests and examples for FixedList See also Foam::FixedList \*---------------------------------------------------------------------------*/ #include "argList.H" #include "FixedList.H" #include "Fstream.H" #include "List.H" #include "IPstream.H" #include "OPstream.H" #include using namespace Foam; template Ostream& printInfo(const FixedList, N>& list) { Info<< list << " addresses:"; for (unsigned i = 0; i < N; ++i) { Info<< ' ' << name(list[i].cdata()); } Info<< nl; return Info; } template Ostream& printInfo ( const FixedList, N>& list1, const FixedList, N>& list2 ) { Info<< "llist1:"; printInfo(list1); Info<< "llist2:"; printInfo(list2); return Info; } template void compileInfo() { // Info<< typeid(decltype(FixedList)).name() << nl; // Info<< " holds: " // << typeid(decltype(FixedList::value_type())).name() << nl; Info<< "max_size:" << FixedList::max_size() << nl; } template typename std::enable_if <(FixedListType::max_size() == 2), bool>::type is_pair() { return true; } template typename std::enable_if<(FixedListType::max_size() != 2), std::string>::type is_pair() { return "not really at all"; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { argList::noCheckProcessorDirectories(); argList::addBoolOption("assign"); argList::addBoolOption("iter"); argList::addBoolOption("swap"); argList::addBoolOption("default", "reinstate default tests"); argList::addBoolOption("no-wait", "test with skipping request waits"); argList::addNote("runs default tests or specified ones only"); #include "setRootCase.H" const bool optNowaiting = args.found("no-wait"); // Run default tests, unless only specific tests are requested const bool defaultTests = ( args.found("default") || args.options().empty() || (optNowaiting && args.options().size()) ); typedef FixedList scalar2Type; typedef FixedList label3Type; // Compile-time info compileInfo(); Info<< "pair: " << is_pair() << nl; Info<< "pair: " << is_pair() << nl; Info<< "max_size:" << scalar2Type::max_size() << nl; if (defaultTests || args.found("iter")) { Info<< nl << "Test iterators" << nl; FixedList ident; std::iota(ident.begin(), ident.end(), 0); // auto iter = ident.begin(); // // iter += 5; // Info << *iter << "< " << nl; // iter -= 2; // Info << *iter << "< " << nl; // Don't yet bother with making reverse iterators random access // auto riter = ident.crbegin(); // riter += 5; // Info << *riter << "< " << nl; // riter += 2; // Info << *riter << "< " << nl; Info<<"Ident:"; forAllConstIters(ident, iter) { Info<<" " << *iter; } Info<< nl; Info<<"reverse:"; forAllReverseIters(ident, iter) { Info<<" " << *iter; } Info<< nl; Info<<"const reverse:"; forAllConstReverseIters(ident, iter) { Info<<" " << *iter; } Info<< nl; } if (defaultTests || args.found("swap")) { Info<< nl << "Test swap" << nl; FixedList list1{2, 3, 4, 5}; Info<< "list1:" << list1 << " hash:" << FixedList::hasher()(list1) << nl << " hash:" << Hash>()(list1) << nl; Info<< "get<0>: " << list1.get<0>() << nl; Info<< "get<1>: " << list1.get<1>() << nl; Info<< "get<2>: " << list1.get<2>() << nl; Info<< "get<3>: " << list1.get<3>() << nl; // Will not compile: Info<< "get<4>: " << list1.get<4>() << nl; // Test deprecated form label array2[4] = {0, 1, 2, 3}; FixedList list2(array2); Info<< "list2:" << list2 << " hash:" << FixedList::hasher()(list2) << nl << " hash:" << Hash>()(list2) << nl; // Test deprecated form SLList