diff --git a/examples/ftp/Ftp.cpp b/examples/ftp/Ftp.cpp index e4de8adc..4a346cc9 100644 --- a/examples/ftp/Ftp.cpp +++ b/examples/ftp/Ftp.cpp @@ -103,8 +103,8 @@ int main() sf::Ftp::ListingResponse response = server.getDirectoryListing(); std::cout << response << std::endl; const std::vector& names = response.getListing(); - for (std::vector::const_iterator it = names.begin(); it != names.end(); ++it) - std::cout << *it << std::endl; + for (const auto& name : names) + std::cout << name << std::endl; break; } diff --git a/include/SFML/Audio/SoundFileFactory.inl b/include/SFML/Audio/SoundFileFactory.inl index 3fb84726..fce1c032 100644 --- a/include/SFML/Audio/SoundFileFactory.inl +++ b/include/SFML/Audio/SoundFileFactory.inl @@ -57,7 +57,7 @@ template void SoundFileFactory::unregisterReader() { // Remove the instance(s) of the reader from the array of factories - for (ReaderFactoryArray::iterator it = s_readers.begin(); it != s_readers.end(); ) + for (auto it = s_readers.begin(); it != s_readers.end(); ) { if (it->create == &priv::createReader) it = s_readers.erase(it); @@ -88,7 +88,7 @@ template void SoundFileFactory::unregisterWriter() { // Remove the instance(s) of the writer from the array of factories - for (WriterFactoryArray::iterator it = s_writers.begin(); it != s_writers.end(); ) + for (auto it = s_writers.begin(); it != s_writers.end(); ) { if (it->create == &priv::createWriter) it = s_writers.erase(it); diff --git a/include/SFML/Network/SocketSelector.hpp b/include/SFML/Network/SocketSelector.hpp index 1936fb54..2900d856 100644 --- a/include/SFML/Network/SocketSelector.hpp +++ b/include/SFML/Network/SocketSelector.hpp @@ -241,9 +241,9 @@ private: /// else /// { /// // The listener socket is not ready, test all other sockets (the clients) -/// for (std::list::iterator it = clients.begin(); it != clients.end(); ++it) +/// for (auto c : clients) /// { -/// sf::TcpSocket& client = **it; +/// sf::TcpSocket& client = *c; /// if (selector.isReady(client)) /// { /// // The client has sent some data, we can receive it diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index c9842048..f412a125 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -72,8 +72,8 @@ SoundBuffer::~SoundBuffer() sounds.swap(m_sounds); // Detach the buffer from the sounds that use it (to avoid OpenAL errors) - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->resetBuffer(); + for (const auto& sound : sounds) + sound->resetBuffer(); // Destroy the buffer if (m_buffer) @@ -257,8 +257,8 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) SoundList sounds(m_sounds); // Detach the buffer from the sounds that use it (to avoid OpenAL errors) - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->resetBuffer(); + for (const auto& sound : sounds) + sound->resetBuffer(); // Fill the buffer ALsizei size = static_cast(m_samples.size()) * sizeof(Int16); @@ -268,8 +268,8 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) m_duration = seconds(static_cast(m_samples.size()) / sampleRate / channelCount); // Now reattach the buffer to the sounds that use it - for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) - (*it)->setBuffer(*this); + for (const auto& sound : sounds) + sound->setBuffer(*this); return true; } diff --git a/src/SFML/Audio/SoundFileFactory.cpp b/src/SFML/Audio/SoundFileFactory.cpp index d2b1fc84..172fa415 100644 --- a/src/SFML/Audio/SoundFileFactory.cpp +++ b/src/SFML/Audio/SoundFileFactory.cpp @@ -76,11 +76,11 @@ std::unique_ptr SoundFileFactory::createReaderFromFilename(cons } // Test the filename in all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -100,11 +100,11 @@ std::unique_ptr SoundFileFactory::createReaderFromMemory(const stream.open(data, sizeInBytes); // Test the stream for all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -120,11 +120,11 @@ std::unique_ptr SoundFileFactory::createReaderFromStream(InputS ensureDefaultReadersWritersRegistered(); // Test the stream for all the registered factories - for (ReaderFactoryArray::const_iterator it = s_readers.begin(); it != s_readers.end(); ++it) + for (const auto& reader : s_readers) { stream.seek(0); - if (it->check(stream)) - return it->create(); + if (reader.check(stream)) + return reader.create(); } // No suitable reader found @@ -140,10 +140,10 @@ std::unique_ptr SoundFileFactory::createWriterFromFilename(cons ensureDefaultReadersWritersRegistered(); // Test the filename in all the registered factories - for (WriterFactoryArray::const_iterator it = s_writers.begin(); it != s_writers.end(); ++it) + for (const auto& writer : s_writers) { - if (it->check(filename)) - return it->create(); + if (writer.check(filename)) + return writer.create(); } // No suitable writer found diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 3d6b01e0..78320da7 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -284,8 +284,8 @@ void SoundStream::streamData() // Create the buffers alCheck(alGenBuffers(BufferCount, m_buffers)); - for (int i = 0; i < BufferCount; ++i) - m_endBuffers[i] = false; + for (auto& buffer : m_endBuffers) + buffer = false; // Fill the queue requestStop = fillQueue(); @@ -337,7 +337,7 @@ void SoundStream::streamData() // Find its number unsigned int bufferNum = 0; - for (int i = 0; i < BufferCount; ++i) + for (auto i = 0; i < BufferCount; ++i) if (m_buffers[i] == buffer) { bufferNum = i; diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 15d50d98..8dc526b9 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -37,6 +37,7 @@ extern "C" #include #include } +#include #include @@ -45,8 +46,7 @@ namespace // Convert a string to lower case std::string toLower(std::string str) { - for (std::string::iterator i = str.begin(); i != str.end(); ++i) - *i = static_cast(std::tolower(*i)); + std::transform(str.begin(), str.end(), str.begin(), ::tolower); return str; } diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index ef6987fb..3d0bd3d7 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -39,8 +39,7 @@ namespace // Convert a string to lower case std::string toLower(std::string str) { - for (std::string::iterator i = str.begin(); i != str.end(); ++i) - *i = static_cast(std::tolower(*i)); + std::transform(str.begin(), str.end(), str.begin(), ::tolower); return str; } } @@ -119,9 +118,9 @@ std::string Http::Request::prepare() const out << "HTTP/" << m_majorVersion << "." << m_minorVersion << "\r\n"; // Write fields - for (FieldTable::const_iterator i = m_fields.begin(); i != m_fields.end(); ++i) + for (const auto& field : m_fields) { - out << i->first << ": " << i->second << "\r\n"; + out << field.first << ": " << field.second << "\r\n"; } // Use an extra \r\n to separate the header from the body diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index fc33355c..8228af77 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -544,8 +544,8 @@ Packet& Packet::operator <<(const std::wstring& data) // Then insert characters if (length > 0) { - for (std::wstring::const_iterator c = data.begin(); c != data.end(); ++c) - *this << static_cast(*c); + for (auto c : data) + *this << static_cast(c); } return *this; @@ -562,8 +562,8 @@ Packet& Packet::operator <<(const String& data) // Then insert characters if (length > 0) { - for (String::ConstIterator c = data.begin(); c != data.end(); ++c) - *this << *c; + for (auto c : data) + *this << c; } return *this;