malachite_base/num/logic/
count_ones.rs

1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::num::logic::traits::CountOnes;
10
11macro_rules! impl_count_ones {
12    ($t:ident) => {
13        impl CountOnes for $t {
14            /// This is a wrapper over the `count_ones` functions in the standard library, for
15            /// example [this one](u32::count_ones).
16            #[inline]
17            fn count_ones(self) -> u64 {
18                u64::from($t::count_ones(self))
19            }
20        }
21    };
22}
23apply_to_primitive_ints!(impl_count_ones);