Skip to content

Examples can (and should) be exemplary C++ #724

@xtofl

Description

@xtofl

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<int> stencil(8);
    stencil[0] = 0;
    stencil[1] = 1;
...

could make use of std::initializer_list<int> 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<bbox,bbox,bbox>

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomers.thrustFor all items related to Thrust.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions