NVIDIA / NVIDIA/cccl

Examples can (and should) be exemplary C++

Open
#724 5 comments 4 reactions 0 assignees View on GitHub
good first issue thrust
Dominant language
C++
Stars
2.5k
Forks
487
Avg merge
2d 7h
Merged PRs (30d)
296

Description

Obviously, the primary goal of the examples is to show how one uses the library.

However, they are also adding to the overall C++ knowledge: people using `thrust` are very likely to also learn the standard library algorithms, and take over the style presented (if not even copy-paste-adapt the examples).

So there would be value in making the example code exemplary, 'modern' C++.

Some instances of example code that could be modernized:

```
thrust::device_vector stencil(8);
stencil[0] = 0;
stencil[1] = 1;
...
```
could make use of `std::initializer_list` to direct initialize the vector.

```
std::cout << "found " << (indices_end - indices.begin()) ...
```
Should really use `std::distance(begin(indices), indices_end)`

```
// reduce a pair of bounding boxes (a,b) to a bounding box containing a and b
struct bbox_reduction : public thrust::binary_function
```
Is a poor choice of name: it tells you what function it's going to be used in (reduce), not what it does (bounding box of bounding boxes); it may be replaced by a lambda expression.

...

I think it would be a good idea to set up an 'example-wide' code review and try to exemplify that code.

(cf. also the very limited pull request NVIDIA/thrust#753)

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing Thrust examples and the referenced NVIDIA/thrust#753 pull request. Inventory modernization opportunities such as initialization, distance calculation, and callable naming; done means the examples consistently present modern, exemplary C++ without changing their teaching purpose.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Refactor
Difficulty
4/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.