lanl / lanl/singularity-eos

Enhancements for `lambda` inputs.

Open
#369 0 comments 0 reactions 1 assignee View on GitHub

@Yurlungur is already working on this.

Since Apr 25, 2024.

clean-up enhancement
Dominant language
C++
Stars
39
Forks
22
Avg merge
10h 22m
Merged PRs (30d)
3

Description

When we switch to C++17 we should use the following model to allow us to pass nullptr into functions for lambda directly. We should also consider switching to std::optional.

template <typename T>
struct remove_cvref {
  typedef std::remove_cv_t<std::remove_reference_t<T>> type;
};
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type;

template<typename T>
constexpr inline bool is_null(T &&t) {
    if constexpr(std::is_pointer<remove_cvref_t<T>>::value) {
        return std::forward<T>(t) == nullptr;
    } else {
        return false;
    }
}

#define SG_DO_IF_NOT_NULL(lambda) \
  if constexpr (!std::is_null_pointer<remove_cvref_t<decltype(lambda)>>::value) \
    if (!is_null(lambda)) 

template<typename T>
void DoSomething(T &&t) {
    SG_DO_IF_NOT_NULL(t) {
        std:: cout << t[0] << std::endl;
    }
}

int main() {

    auto q = nullptr;
    std::vector<Real> v = {1, 2, 3, 4};
    DoSomething(v);
    DoSomething(q);

    return 0;
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.