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:

C++17 includes the following new standard library features:

C++14 includes the following new language features:

C++14 includes the following new standard library features:

C++11 includes the following new language features:

C++11 includes the following new standard library features:

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:

  • a distill-style blog post
  • What MoFEM offers?
  • a post with code diff
  • Google Gemini updates: Flash 1.5, Gemma 2 and Project Astra
  • a post with code