Skip to content

Commit fe63aa2

Browse files
authored
refactor: Switch to trailing return types (#599)
- Trailing return types everywhere - Optionally, return type deduction where sensible (simple and short functions) This is related to introduction of common .clang-format, see #596 (comment)
1 parent 95679b6 commit fe63aa2

58 files changed

Lines changed: 650 additions & 545 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/boost/gil/algorithm.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,38 +89,38 @@ struct binary_operation_obj
8989
using result_type = Result;
9090

9191
template <typename V1, typename V2> BOOST_FORCEINLINE
92-
result_type operator()(const std::pair<const V1*,const V2*>& p) const {
92+
auto operator()(const std::pair<const V1*,const V2*>& p) const -> result_type {
9393
return apply(*p.first, *p.second, typename views_are_compatible<V1,V2>::type());
9494
}
9595

9696
template <typename V1, typename V2> BOOST_FORCEINLINE
97-
result_type operator()(const V1& v1, const V2& v2) const {
97+
auto operator()(const V1& v1, const V2& v2) const -> result_type {
9898
return apply(v1, v2, typename views_are_compatible<V1,V2>::type());
9999
}
100100

101-
result_type operator()(const error_t&) const { throw std::bad_cast(); }
101+
auto operator()(const error_t&) const -> result_type { throw std::bad_cast(); }
102102
private:
103103

104104
// dispatch from apply overload to a function with distinct name
105105
template <typename V1, typename V2>
106106
BOOST_FORCEINLINE
107-
result_type apply(V1 const& v1, V2 const& v2, std::false_type) const
107+
auto apply(V1 const& v1, V2 const& v2, std::false_type) const -> result_type
108108
{
109109
return ((const Derived*)this)->apply_incompatible(v1, v2);
110110
}
111111

112112
// dispatch from apply overload to a function with distinct name
113113
template <typename V1, typename V2>
114114
BOOST_FORCEINLINE
115-
result_type apply(V1 const& v1, V2 const& v2, std::true_type) const
115+
auto apply(V1 const& v1, V2 const& v2, std::true_type) const -> result_type
116116
{
117117
return ((const Derived*)this)->apply_compatible(v1, v2);
118118
}
119119

120120
// function with distinct name - it can be overloaded by subclasses
121121
template <typename V1, typename V2>
122122
BOOST_FORCEINLINE
123-
result_type apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const
123+
auto apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const -> result_type
124124
{
125125
throw std::bad_cast();
126126
}
@@ -155,9 +155,10 @@ auto copy(
155155
/// \ingroup STLOptimizations
156156
/// \brief Copy when both src and dst are interleaved and of the same type can be just memmove
157157
template<typename T, typename CS>
158-
BOOST_FORCEINLINE boost::gil::pixel<T,CS>*
159-
copy(const boost::gil::pixel<T,CS>* first, const boost::gil::pixel<T,CS>* last,
160-
boost::gil::pixel<T,CS>* dst) {
158+
BOOST_FORCEINLINE
159+
auto copy(const boost::gil::pixel<T,CS>* first, const boost::gil::pixel<T,CS>* last,
160+
boost::gil::pixel<T,CS>* dst) -> boost::gil::pixel<T,CS>*
161+
{
161162
return (boost::gil::pixel<T,CS>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
162163
}
163164
} // namespace std
@@ -174,7 +175,8 @@ namespace std {
174175
/// \ingroup STLOptimizations
175176
/// \brief Copy when both src and dst are planar pointers is copy for each channel
176177
template<typename CS, typename IC1, typename IC2> BOOST_FORCEINLINE
177-
boost::gil::planar_pixel_iterator<IC2,CS> copy(boost::gil::planar_pixel_iterator<IC1,CS> first, boost::gil::planar_pixel_iterator<IC1,CS> last, boost::gil::planar_pixel_iterator<IC2,CS> dst) {
178+
auto copy(boost::gil::planar_pixel_iterator<IC1,CS> first, boost::gil::planar_pixel_iterator<IC1,CS> last, boost::gil::planar_pixel_iterator<IC2,CS> dst) -> boost::gil::planar_pixel_iterator<IC2,CS>
179+
{
178180
boost::gil::gil_function_requires<boost::gil::ChannelsCompatibleConcept<typename std::iterator_traits<IC1>::value_type,typename std::iterator_traits<IC2>::value_type>>();
179181
static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>());
180182
return dst+(last-first);
@@ -250,7 +252,7 @@ struct copier_n<iterator_from_2d<IL>,iterator_from_2d<OL>> {
250252
};
251253

252254
template <typename SrcIterator, typename DstIterator>
253-
BOOST_FORCEINLINE DstIterator copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) {
255+
BOOST_FORCEINLINE auto copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) -> DstIterator {
254256
using src_x_iterator = typename SrcIterator::x_iterator;
255257
using dst_x_iterator = typename DstIterator::x_iterator;
256258

@@ -276,9 +278,11 @@ namespace std {
276278
/// \ingroup STLOptimizations
277279
/// \brief std::copy(I1,I1,I2) with I1 and I2 being a iterator_from_2d
278280
template <typename IL, typename OL>
279-
BOOST_FORCEINLINE boost::gil::iterator_from_2d<OL> copy1(boost::gil::iterator_from_2d<IL> first, boost::gil::iterator_from_2d<IL> last, boost::gil::iterator_from_2d<OL> dst) {
281+
BOOST_FORCEINLINE auto copy1(boost::gil::iterator_from_2d<IL> first, boost::gil::iterator_from_2d<IL> last, boost::gil::iterator_from_2d<OL> dst) -> boost::gil::iterator_from_2d<OL>
282+
{
280283
return boost::gil::detail::copy_with_2d_iterators(first,last,dst);
281284
}
285+
282286
} // namespace std
283287

284288
namespace boost { namespace gil {
@@ -313,13 +317,13 @@ class copy_and_convert_pixels_fn : public binary_operation_obj<copy_and_convert_
313317
copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {}
314318
// when the two color spaces are incompatible, a color conversion is performed
315319
template <typename V1, typename V2> BOOST_FORCEINLINE
316-
result_type apply_incompatible(const V1& src, const V2& dst) const {
320+
auto apply_incompatible(const V1& src, const V2& dst) const -> result_type {
317321
copy_pixels(color_converted_view<typename V2::value_type>(src,_cc),dst);
318322
}
319323

320324
// If the two color spaces are compatible, copy_and_convert is just copy
321325
template <typename V1, typename V2> BOOST_FORCEINLINE
322-
result_type apply_compatible(const V1& src, const V2& dst) const {
326+
auto apply_compatible(const V1& src, const V2& dst) const -> result_type {
323327
copy_pixels(src,dst);
324328
}
325329
};

include/boost/gil/bit_aligned_pixel_iterator.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ struct bit_aligned_pixel_iterator : public iterator_facade<bit_aligned_pixel_ite
6363

6464
/// For some reason operator[] provided by iterator_adaptor returns a custom class that is convertible to reference
6565
/// We require our own reference because it is registered in iterator_traits
66-
reference operator[](difference_type d) const { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
66+
auto operator[](difference_type d) const -> reference { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
6767

68-
reference operator->() const { return **this; }
69-
const bit_range_t& bit_range() const { return _bit_range; }
70-
bit_range_t& bit_range() { return _bit_range; }
68+
auto operator->() const -> reference { return **this; }
69+
auto bit_range() const -> bit_range_t const& { return _bit_range; }
70+
auto bit_range() -> bit_range_t& { return _bit_range; }
7171
private:
7272
bit_range_t _bit_range;
7373
static constexpr int bit_size = NonAlignedPixelReference::bit_size;
7474

7575
friend class boost::iterator_core_access;
76-
reference dereference() const { return NonAlignedPixelReference(_bit_range); }
76+
auto dereference() const -> reference { return NonAlignedPixelReference(_bit_range); }
7777
void increment() { ++_bit_range; }
7878
void decrement() { --_bit_range; }
7979
void advance(difference_type d) { _bit_range.bit_advance(d*bit_size); }
8080

81-
difference_type distance_to(const bit_aligned_pixel_iterator& it) const { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
81+
auto distance_to(bit_aligned_pixel_iterator const& it) const -> difference_type { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
8282
bool equal(const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; }
8383
};
8484

@@ -122,12 +122,14 @@ struct byte_to_memunit<bit_aligned_pixel_iterator<NonAlignedPixelReference>>
122122
{};
123123

124124
template <typename NonAlignedPixelReference>
125-
inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) {
125+
inline auto memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) -> std::ptrdiff_t
126+
{
126127
return NonAlignedPixelReference::bit_size;
127128
}
128129

129130
template <typename NonAlignedPixelReference>
130-
inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) {
131+
inline auto memunit_distance(bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p1, bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p2) -> std::ptrdiff_t
132+
{
131133
return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset();
132134
}
133135

@@ -137,14 +139,15 @@ inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>
137139
}
138140

139141
template <typename NonAlignedPixelReference>
140-
inline bit_aligned_pixel_iterator<NonAlignedPixelReference> memunit_advanced(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
142+
inline auto memunit_advanced(bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p, std::ptrdiff_t diff) -> bit_aligned_pixel_iterator<NonAlignedPixelReference> {
141143
bit_aligned_pixel_iterator<NonAlignedPixelReference> ret=p;
142144
memunit_advance(ret, diff);
143145
return ret;
144146
}
145147

146148
template <typename NonAlignedPixelReference> inline
147-
NonAlignedPixelReference memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) {
149+
auto memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) -> NonAlignedPixelReference
150+
{
148151
return *memunit_advanced(it,diff);
149152
}
150153
/////////////////////////////
@@ -183,11 +186,14 @@ namespace std {
183186
// It is important to provide an overload of uninitialized_copy for bit_aligned_pixel_iterator. The default STL implementation calls placement new,
184187
// which is not defined for bit_aligned_pixel_iterator.
185188
template <typename NonAlignedPixelReference>
186-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
187-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
188-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst) {
189+
auto uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
190+
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
191+
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst)
192+
-> boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference>
193+
{
189194
return std::copy(first,last,dst);
190195
}
191196

192-
} // namespace std
197+
} // namespace std
198+
193199
#endif

include/boost/gil/bit_aligned_pixel_reference.hpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ class bit_range {
4949
BOOST_ASSERT(bit_offset >= 0 && bit_offset < 8);
5050
}
5151

52-
bit_range(const bit_range& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
52+
bit_range(bit_range const& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
5353
template <bool M> bit_range(const bit_range<RangeSize,M>& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
5454

55-
bit_range& operator=(const bit_range& br) { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; }
56-
bool operator==(const bit_range& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; }
55+
auto operator=(bit_range const& br) -> bit_range& { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; }
56+
bool operator==(bit_range const& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; }
5757

58-
bit_range& operator++() {
58+
auto operator++() -> bit_range& {
5959
_current_byte += (_bit_offset+RangeSize) / 8;
6060
_bit_offset = (_bit_offset+RangeSize) % 8;
6161
return *this;
6262
}
63-
bit_range& operator--() { bit_advance(-RangeSize); return *this; }
63+
auto operator--() -> bit_range& { bit_advance(-RangeSize); return *this; }
6464

6565
void bit_advance(difference_type num_bits) {
6666
int new_offset = int(_bit_offset+num_bits);
@@ -71,11 +71,13 @@ class bit_range {
7171
--_current_byte;
7272
}
7373
}
74-
difference_type bit_distance_to(const bit_range& b) const {
74+
75+
auto bit_distance_to(bit_range const& b) const -> difference_type
76+
{
7577
return (b.current_byte() - current_byte())*8 + b.bit_offset()-bit_offset();
7678
}
77-
byte_t* current_byte() const { return _current_byte; }
78-
int bit_offset() const { return _bit_offset; }
79+
auto current_byte() const -> byte_t* { return _current_byte; }
80+
auto bit_offset() const -> int { return _bit_offset; }
7981
};
8082

8183
/// \defgroup ColorBaseModelNonAlignedPixel bit_aligned_pixel_reference
@@ -136,8 +138,10 @@ struct bit_aligned_pixel_reference
136138

137139
bit_aligned_pixel_reference(){}
138140
bit_aligned_pixel_reference(data_ptr_t data_ptr, int bit_offset) : _bit_range(data_ptr, bit_offset) {}
139-
explicit bit_aligned_pixel_reference(const bit_range_t& bit_range) : _bit_range(bit_range) {}
140-
template <bool IsMutable2> bit_aligned_pixel_reference(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2>& p) : _bit_range(p._bit_range) {}
141+
explicit bit_aligned_pixel_reference(bit_range_t const& bit_range) : _bit_range(bit_range) {}
142+
143+
template <bool IsMutable2>
144+
bit_aligned_pixel_reference(bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2> const& p) : _bit_range(p._bit_range) {}
141145

142146
// Grayscale references can be constructed from the channel reference
143147
explicit bit_aligned_pixel_reference(typename kth_element_type<bit_aligned_pixel_reference,0>::type const channel0)
@@ -183,11 +187,12 @@ struct bit_aligned_pixel_reference
183187

184188
auto operator->() const -> bit_aligned_pixel_reference const* { return this; }
185189

186-
bit_range_t const& bit_range() const { return _bit_range; }
190+
auto bit_range() const -> bit_range_t const& { return _bit_range; }
187191

188192
private:
189193
mutable bit_range_t _bit_range;
190-
template <typename B, typename C, typename L, bool M> friend struct bit_aligned_pixel_reference;
194+
template <typename B, typename C, typename L, bool M>
195+
friend struct bit_aligned_pixel_reference;
191196

192197
template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,bit_aligned_pixel_reference> >(); }
193198

@@ -369,7 +374,7 @@ namespace std {
369374
// Having three overloads allows us to swap between different (but compatible) models of PixelConcept
370375

371376
template <typename B, typename C, typename L, typename R> inline
372-
void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, R& y) {
377+
void swap(boost::gil::bit_aligned_pixel_reference<B,C,L,true> const x, R& y) {
373378
boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
374379
}
375380

@@ -381,7 +386,7 @@ void swap(typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_ty
381386

382387

383388
template <typename B, typename C, typename L> inline
384-
void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
389+
void swap(boost::gil::bit_aligned_pixel_reference<B,C,L,true> const x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
385390
boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
386391
}
387392

0 commit comments

Comments
 (0)