Programming C++ with MoFEM
An extensive list of C++ standards features can be found here (Under this link).
C++17 includes the following new language features:
- template argument deduction for class templates
- declaring non-type template parameters with auto
- folding expressions
- new rules for auto deduction from braced-init-list
- constexpr lambda
- lambda capture this by value
- inline variables
- nested namespaces
- structured bindings
- selection statements with initializer
- constexpr if
- utf-8 character literals
- direct-list-initialization of enums
- fallthrough, nodiscard, maybe_unused attributes
- __has_include
C++17 includes the following new standard library features:
- std::variant
- std::optional
- std::any
- std::string_view
- std::invoke
- std::apply
- std::filesystem
- std::byte
- splicing for maps and sets
- parallel algorithms
C++14 includes the following new language features:
- binary literals
- generic lambda expressions
- lambda capture initializers
- return type deduction
- decltype(auto)
- relaxing constraints on constexpr functions
- variable templates
- [[deprecated]] attribute
C++14 includes the following new standard library features:
C++11 includes the following new language features:
- move semantics
- variadic templates
- rvalue references
- forwarding references
- initializer lists
- static assertions
- auto
- lambda expressions
- decltype
- type aliases
- nullptr
- strongly-typed enums
- attributes
- constexpr
- delegating constructors
- user-defined literals
- explicit virtual overrides
- final specifier
- default functions
- deleted functions
- range-based for loops
- special member functions for move semantics
- converting constructors
- explicit conversion functions
- inline-namespaces
- non-static data member initializers
- right angle brackets
- ref-qualified member functions
- trailing return types
- noexcept specifier
- char32_t and char16_t
- raw string literals
C++11 includes the following new standard library features:
- std::move
- std::forward
- std::thread
- std::to_string
- type traits
- smart pointers
- std::chrono
- tuples
- std::tie
- std::array
- unordered containers
- std::make_shared
- std::ref
- memory model
- std::async
- std::begin/end
Modern C++17 standard features used by MoFEM
Modern C++14 standard features used by MoFEM
return type deduction
Using an auto
return type in C++14, the compiler will attempt to deduce the type for you. With lambdas, you can now deduce its return type using auto
, which makes returning a deduced reference or rvalue reference possible.
inline auto getBcEntsPtr() {
return boost::shared_ptr<Range>(shared_from_this(), &bcEnts);
}
decltype(auto)
The decltype(auto)
type-specifier also deduces a type like auto
does. However, it deduces return types while keeping their references and cv-qualifiers (const
and volatile
), while auto
will not.
auto dit = p_miit->numeredColDofsPtr->lower_bound(uid);
decltype(dit) hi_dit;
Modern C++11 standard features used by MoFEM
move semantics
Moving an object means to transfer ownership of some resource it manages to another object.
The first benefit of move semantics is performance optimization. When an object is about to reach the end of its lifetime, either because it’s a temporary or by explicitly calling std::move
, a move is often a cheaper way to transfer resources. For example, moving a std::vector
is just copying some pointers and internal state over to the new vector – copying would involve having to copy every single contained element in the vector, which is expensive and unnecessary if the old vector will soon be destroyed.
// preprocess
for (auto &bit : ts_ctx->preProcessIFunction) {
bit->vecAssembleSwitch = boost::move(ts_ctx->vecAssembleSwitch);
set(*bit);
CHKERR ts_ctx->mField.problem_basic_method_preProcess(ts_ctx->problemName,
*bit);
unset(*bit);
ts_ctx->vecAssembleSwitch = boost::move(bit->vecAssembleSwitch);
}
Enjoy Reading This Article?
Here are some more articles you might like to read next: