• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::count
2
3```cpp
4template<typename KeyT>
5size_type count(KeyT&& key) const;
6```
7
8Returns the number of elements with key `key`. If `ObjectType` is the default `std::map` type, the return value will
9always be `0` (`key` was not found) or `1` (`key` was found).
10
11## Template parameters
12
13`KeyT`
14:   A type for an object key.
15
16## Parameters
17
18`key` (in)
19:   key value of the element to count.
20
21## Return value
22
23Number of elements with key `key`. If the JSON value is not an object, the return value will be `0`.
24
25## Exception safety
26
27Strong exception safety: if an exception occurs, the original value stays intact.
28
29## Complexity
30
31Logarithmic in the size of the JSON object.
32
33## Notes
34
35This method always returns `0` when executed on a JSON type that is not an object.
36
37## Example
38
39??? example
40
41    The example shows how `count()` is used.
42
43    ```cpp
44    --8<-- "examples/count.cpp"
45    ```
46
47    Output:
48
49    ```json
50    --8<-- "examples/count.output"
51    ```
52
53## Version history
54
55- Added in version 1.0.0.
56