From f03a415121abe70e2e9ef7ccbdeb19c2d2722100 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 7 Dec 2021 22:57:26 +0300 Subject: [PATCH] Use std::vector.data() where appropriate --- examples/island/Island.cpp | 8 ++-- examples/voip/Server.cpp | 2 +- examples/vulkan/Vulkan.cpp | 50 +++++++++++------------ src/SFML/Audio/Music.cpp | 4 +- src/SFML/Audio/SoundBuffer.cpp | 8 ++-- src/SFML/Audio/SoundBufferRecorder.cpp | 2 +- src/SFML/Audio/SoundFileWriterFlac.cpp | 2 +- src/SFML/Audio/SoundRecorder.cpp | 4 +- src/SFML/Graphics/Font.cpp | 4 +- src/SFML/Graphics/Image.cpp | 10 ++--- src/SFML/Graphics/ImageLoader.cpp | 22 +++++----- src/SFML/Graphics/Shader.cpp | 34 +++++++-------- src/SFML/Graphics/Texture.cpp | 12 +++--- src/SFML/Graphics/VertexArray.cpp | 2 +- src/SFML/Network/Packet.cpp | 2 +- src/SFML/Network/TcpSocket.cpp | 10 ++--- src/SFML/Network/UdpSocket.cpp | 4 +- src/SFML/Window/FreeBSD/JoystickImpl.cpp | 6 +-- src/SFML/Window/NetBSD/JoystickImpl.cpp | 6 +-- src/SFML/Window/OSX/JoystickImpl.cpp | 4 +- src/SFML/Window/OSX/SFContext.mm | 2 +- src/SFML/Window/Unix/ClipboardImpl.cpp | 2 +- src/SFML/Window/Unix/CursorImpl.cpp | 4 +- src/SFML/Window/Unix/GlxContext.cpp | 2 +- src/SFML/Window/Unix/VulkanImplX11.cpp | 2 +- src/SFML/Window/Unix/WindowImplX11.cpp | 14 +++---- src/SFML/Window/Win32/VulkanImplWin32.cpp | 2 +- src/SFML/Window/Win32/WglContext.cpp | 2 +- src/SFML/Window/Win32/WindowImplWin32.cpp | 2 +- 29 files changed, 113 insertions(+), 115 deletions(-) diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 1ec46cb3a..3df5a221b 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -142,7 +142,7 @@ int main() terrainStagingBuffer.resize(resolutionX * resolutionY * 6); // Generate the initial terrain - generateTerrain(&terrainStagingBuffer[0]); + generateTerrain(terrainStagingBuffer.data()); statusText.setString("Generating Terrain..."); } @@ -189,7 +189,7 @@ int main() { switch (event.key.code) { - case sf::Keyboard::Return: generateTerrain(&terrainStagingBuffer[0]); break; + case sf::Keyboard::Return: generateTerrain(terrainStagingBuffer.data()); break; case sf::Keyboard::Down: currentSetting = (currentSetting + 1) % settingCount; break; case sf::Keyboard::Up: currentSetting = (currentSetting + settingCount - 1) % settingCount; break; case sf::Keyboard::Left: *(settings[currentSetting].value) -= 0.1f; break; @@ -215,7 +215,7 @@ int main() // If there is new data pending to be uploaded to the VertexBuffer, do it now if (bufferUploadPending) { - terrain.update(&terrainStagingBuffer[0]); + terrain.update(terrainStagingBuffer.data()); bufferUploadPending = false; } @@ -513,7 +513,7 @@ void processWorkItem(std::vector& vertices, const WorkItem& workItem } // Copy the resulting geometry from our thread-local buffer into the target buffer - std::memcpy(workItem.targetBuffer + (resolutionX * rowStart * 6), &vertices[0], sizeof(sf::Vertex) * resolutionX * rowCount * 6); + std::memcpy(workItem.targetBuffer + (resolutionX * rowStart * 6), vertices.data(), sizeof(sf::Vertex) * resolutionX * rowCount * 6); } diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 12f0f979e..a93cd7df0 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -89,7 +89,7 @@ private: } // Fill audio data to pass to the stream - data.samples = &m_tempBuffer[0]; + data.samples = m_tempBuffer.data(); data.sampleCount = m_tempBuffer.size(); // Update the playing offset diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 2d2ad2f70..befd71c8d 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -341,7 +341,7 @@ public: vkWaitForFences(device, 1, &fences[i], VK_TRUE, std::numeric_limits::max()); if (commandBuffers.size()) - vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), &commandBuffers[0]); + vkFreeCommandBuffers(device, commandPool, static_cast(commandBuffers.size()), commandBuffers.data()); commandBuffers.clear(); @@ -424,7 +424,7 @@ public: layers.resize(objectCount); - if (vkEnumerateInstanceLayerProperties(&objectCount, &layers[0]) != VK_SUCCESS) + if (vkEnumerateInstanceLayerProperties(&objectCount, layers.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -486,7 +486,7 @@ public: requiredExtentions.pop_back(); instanceCreateInfo.enabledExtensionCount = static_cast(requiredExtentions.size()); - instanceCreateInfo.ppEnabledExtensionNames = &requiredExtentions[0]; + instanceCreateInfo.ppEnabledExtensionNames = requiredExtentions.data(); result = vkCreateInstance(&instanceCreateInfo, 0, &instance); } @@ -553,7 +553,7 @@ public: devices.resize(objectCount); - if (vkEnumeratePhysicalDevices(instance, &objectCount, &devices[0]) != VK_SUCCESS) + if (vkEnumeratePhysicalDevices(instance, &objectCount, devices.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -575,7 +575,7 @@ public: extensions.resize(objectCount); - if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, &extensions[0]) != VK_SUCCESS) + if (vkEnumerateDeviceExtensionProperties(devices[i], 0, &objectCount, extensions.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -659,7 +659,7 @@ public: queueFamilyProperties.resize(objectCount); - vkGetPhysicalDeviceQueueFamilyProperties(gpu, &objectCount, &queueFamilyProperties[0]); + vkGetPhysicalDeviceQueueFamilyProperties(gpu, &objectCount, queueFamilyProperties.data()); for (std::size_t i = 0; i < queueFamilyProperties.size(); i++) { @@ -730,7 +730,7 @@ public: surfaceFormats.resize(objectCount); - if (vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &objectCount, &surfaceFormats[0]) != VK_SUCCESS) + if (vkGetPhysicalDeviceSurfaceFormatsKHR(gpu, surface, &objectCount, surfaceFormats.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -774,7 +774,7 @@ public: presentModes.resize(objectCount); - if (vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &objectCount, &presentModes[0]) != VK_SUCCESS) + if (vkGetPhysicalDeviceSurfacePresentModesKHR(gpu, surface, &objectCount, presentModes.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -845,7 +845,7 @@ public: swapchainImages.resize(objectCount); swapchainImageViews.resize(objectCount); - if (vkGetSwapchainImagesKHR(device, swapchain, &objectCount, &swapchainImages[0]) != VK_SUCCESS) + if (vkGetSwapchainImagesKHR(device, swapchain, &objectCount, swapchainImages.data()) != VK_SUCCESS) { vulkanAvailable = false; return; @@ -896,14 +896,14 @@ public: std::vector buffer(static_cast(file.getSize()) / sizeof(uint32_t)); - if (file.read(&buffer[0], file.getSize()) != file.getSize()) + if (file.read(buffer.data(), file.getSize()) != file.getSize()) { vulkanAvailable = false; return; } shaderModuleCreateInfo.codeSize = buffer.size() * sizeof(uint32_t); - shaderModuleCreateInfo.pCode = &buffer[0]; + shaderModuleCreateInfo.pCode = buffer.data(); if (vkCreateShaderModule(device, &shaderModuleCreateInfo, 0, &vertexShaderModule) != VK_SUCCESS) { @@ -924,14 +924,14 @@ public: std::vector buffer(static_cast(file.getSize()) / sizeof(uint32_t)); - if (file.read(&buffer[0], file.getSize()) != file.getSize()) + if (file.read(buffer.data(), file.getSize()) != file.getSize()) { vulkanAvailable = false; return; } shaderModuleCreateInfo.codeSize = buffer.size() * sizeof(uint32_t); - shaderModuleCreateInfo.pCode = &buffer[0]; + shaderModuleCreateInfo.pCode = buffer.data(); if (vkCreateShaderModule(device, &shaderModuleCreateInfo, 0, &fragmentShaderModule) != VK_SUCCESS) { @@ -981,22 +981,20 @@ public: attachmentDescriptions[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; attachmentDescriptions[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - VkAttachmentReference attachmentReferences[2]; + VkAttachmentReference colorAttachmentReference = {}; + colorAttachmentReference.attachment = 0; + colorAttachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - attachmentReferences[0] = VkAttachmentReference(); - attachmentReferences[0].attachment = 0; - attachmentReferences[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - - attachmentReferences[1] = VkAttachmentReference(); - attachmentReferences[1].attachment = 1; - attachmentReferences[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + VkAttachmentReference depthStencilAttachmentReference = {}; + depthStencilAttachmentReference.attachment = 1; + depthStencilAttachmentReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Set up the renderpass to depend on commands that execute before the renderpass begins VkSubpassDescription subpassDescription = VkSubpassDescription(); subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpassDescription.colorAttachmentCount = 1; - subpassDescription.pColorAttachments = &attachmentReferences[0]; - subpassDescription.pDepthStencilAttachment = &attachmentReferences[1]; + subpassDescription.pColorAttachments = &colorAttachmentReference; + subpassDescription.pDepthStencilAttachment = &depthStencilAttachmentReference; VkSubpassDependency subpassDependency = VkSubpassDependency(); subpassDependency.srcSubpass = VK_SUBPASS_EXTERNAL; @@ -2109,11 +2107,11 @@ public: descriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; descriptorSetAllocateInfo.descriptorPool = descriptorPool; descriptorSetAllocateInfo.descriptorSetCount = static_cast(swapchainImages.size()); - descriptorSetAllocateInfo.pSetLayouts = &descriptorSetLayouts[0]; + descriptorSetAllocateInfo.pSetLayouts = descriptorSetLayouts.data(); descriptorSets.resize(swapchainImages.size()); - if (vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, &descriptorSets[0]) != VK_SUCCESS) + if (vkAllocateDescriptorSets(device, &descriptorSetAllocateInfo, descriptorSets.data()) != VK_SUCCESS) { descriptorSets.clear(); @@ -2175,7 +2173,7 @@ public: commandBufferAllocateInfo.commandBufferCount = static_cast(commandBuffers.size()); // Allocate the command buffers from our command pool - if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffers[0]) != VK_SUCCESS) + if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, commandBuffers.data()) != VK_SUCCESS) { commandBuffers.clear(); vulkanAvailable = false; diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index d375ef88d..c0b375909 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -192,8 +192,8 @@ bool Music::onGetData(SoundStream::Chunk& data) toFill = static_cast(loopEnd - currentOffset); // Fill the chunk parameters - data.samples = &m_samples[0]; - data.sampleCount = static_cast(m_file.read(&m_samples[0], toFill)); + data.samples = m_samples.data(); + data.sampleCount = static_cast(m_file.read(m_samples.data(), toFill)); currentOffset += data.sampleCount; // Check if we have stopped obtaining samples or reached either the EOF or the loop end point diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index beb79f3c5..b551a8f99 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -148,7 +148,7 @@ bool SoundBuffer::saveToFile(const std::string& filename) const if (file.openFromFile(filename, getSampleRate(), getChannelCount())) { // Write the samples to the opened file - file.write(&m_samples[0], m_samples.size()); + file.write(m_samples.data(), m_samples.size()); return true; } @@ -162,7 +162,7 @@ bool SoundBuffer::saveToFile(const std::string& filename) const //////////////////////////////////////////////////////////// const Int16* SoundBuffer::getSamples() const { - return m_samples.empty() ? nullptr : &m_samples[0]; + return m_samples.empty() ? nullptr : m_samples.data(); } @@ -224,7 +224,7 @@ bool SoundBuffer::initialize(InputSoundFile& file) // Read the samples from the provided file m_samples.resize(static_cast(sampleCount)); - if (file.read(&m_samples[0], sampleCount) == sampleCount) + if (file.read(m_samples.data(), sampleCount) == sampleCount) { // Update the internal buffer with the new samples return update(channelCount, sampleRate); @@ -262,7 +262,7 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) // Fill the buffer ALsizei size = static_cast(m_samples.size() * sizeof(Int16)); - alCheck(alBufferData(m_buffer, format, &m_samples[0], size, static_cast(sampleRate))); + alCheck(alBufferData(m_buffer, format, m_samples.data(), size, static_cast(sampleRate))); // Compute the duration m_duration = seconds(static_cast(m_samples.size()) / static_cast(sampleRate) / static_cast(channelCount)); diff --git a/src/SFML/Audio/SoundBufferRecorder.cpp b/src/SFML/Audio/SoundBufferRecorder.cpp index 81eb938c6..b3ce4d2f1 100644 --- a/src/SFML/Audio/SoundBufferRecorder.cpp +++ b/src/SFML/Audio/SoundBufferRecorder.cpp @@ -63,7 +63,7 @@ bool SoundBufferRecorder::onProcessSamples(const Int16* samples, std::size_t sam void SoundBufferRecorder::onStop() { if (!m_samples.empty()) - m_buffer.loadFromSamples(&m_samples[0], m_samples.size(), getChannelCount(), getSampleRate()); + m_buffer.loadFromSamples(m_samples.data(), m_samples.size(), getChannelCount(), getSampleRate()); } diff --git a/src/SFML/Audio/SoundFileWriterFlac.cpp b/src/SFML/Audio/SoundFileWriterFlac.cpp index a7d50fcd9..405d91ffb 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.cpp +++ b/src/SFML/Audio/SoundFileWriterFlac.cpp @@ -113,7 +113,7 @@ void SoundFileWriterFlac::write(const Int16* samples, Uint64 count) m_samples32.assign(samples, samples + frames * m_channelCount); // Write them to the FLAC stream - FLAC__stream_encoder_process_interleaved(m_encoder, &m_samples32[0], frames); + FLAC__stream_encoder_process_interleaved(m_encoder, m_samples32.data(), frames); // Next chunk count -= m_samples32.size(); diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 72416878e..6c1b0968d 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -301,10 +301,10 @@ void SoundRecorder::processCapturedSamples() { // Get the recorded samples m_samples.resize(static_cast(samplesAvailable) * getChannelCount()); - alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable); + alcCaptureSamples(captureDevice, m_samples.data(), samplesAvailable); // Forward them to the derived class - if (!onProcessSamples(&m_samples[0], m_samples.size())) + if (!onProcessSamples(m_samples.data(), m_samples.size())) { // The user wants to stop the capture m_isCapturing = false; diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index d7591f0c9..1cd012630 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -672,7 +672,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f // Resize the pixel buffer to the new size and fill it with transparent white pixels m_pixelBuffer.resize(width * height * 4); - Uint8* current = &m_pixelBuffer[0]; + Uint8* current = m_pixelBuffer.data(); Uint8* end = current + width * height * 4; while (current != end) @@ -719,7 +719,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f unsigned int y = static_cast(glyph.textureRect.top) - padding; unsigned int w = static_cast(glyph.textureRect.width) + 2 * padding; unsigned int h = static_cast(glyph.textureRect.height) + 2 * padding; - page.texture.update(&m_pixelBuffer[0], w, h, x, y); + page.texture.update(m_pixelBuffer.data(), w, h, x, y); } // Delete the FT glyph diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 949c27b82..53846e595 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -61,7 +61,7 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) std::vector newPixels(width * height * 4); // Fill it with the specified color - Uint8* ptr = &newPixels[0]; + Uint8* ptr = newPixels.data(); Uint8* end = ptr + newPixels.size(); while (ptr < end) { @@ -174,7 +174,7 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha) if (!m_pixels.empty()) { // Replace the alpha of the pixels that match the transparent color - Uint8* ptr = &m_pixels[0]; + Uint8* ptr = m_pixels.data(); Uint8* end = ptr + m_pixels.size(); while (ptr < end) { @@ -225,8 +225,8 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co unsigned int rows = height; int srcStride = static_cast(source.m_size.x) * 4; int dstStride = static_cast(m_size.x) * 4; - const Uint8* srcPixels = &source.m_pixels[0] + (static_cast(srcRect.left) + static_cast(srcRect.top) * source.m_size.x) * 4; - Uint8* dstPixels = &m_pixels[0] + (destX + destY * m_size.x) * 4; + const Uint8* srcPixels = source.m_pixels.data() + (static_cast(srcRect.left) + static_cast(srcRect.top) * source.m_size.x) * 4; + Uint8* dstPixels = m_pixels.data() + (destX + destY * m_size.x) * 4; // Copy the pixels if (applyAlpha) @@ -289,7 +289,7 @@ const Uint8* Image::getPixelsPtr() const { if (!m_pixels.empty()) { - return &m_pixels[0]; + return m_pixels.data(); } else { diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index 619806f0f..a9e7475bf 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -123,7 +123,7 @@ bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector(width * height * 4)); - memcpy(&pixels[0], ptr, pixels.size()); + memcpy(pixels.data(), ptr, pixels.size()); } // Free the loaded pixels (they are now in our own pixel buffer) @@ -167,7 +167,7 @@ bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, st { // Copy the loaded pixels to the pixel buffer pixels.resize(static_cast(width * height * 4)); - memcpy(&pixels[0], ptr, pixels.size()); + memcpy(pixels.data(), ptr, pixels.size()); } // Free the loaded pixels (they are now in our own pixel buffer) @@ -222,7 +222,7 @@ bool ImageLoader::loadImageFromStream(InputStream& stream, std::vector& p { // Copy the loaded pixels to the pixel buffer pixels.resize(static_cast(width * height * 4)); - memcpy(&pixels[0], ptr, pixels.size()); + memcpy(pixels.data(), ptr, pixels.size()); } // Free the loaded pixels (they are now in our own pixel buffer) @@ -256,25 +256,25 @@ bool ImageLoader::saveImageToFile(const std::string& filename, const std::vector if (extension == "bmp") { // BMP format - if (stbi_write_bmp(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0])) + if (stbi_write_bmp(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) return true; } else if (extension == "tga") { // TGA format - if (stbi_write_tga(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0])) + if (stbi_write_tga(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data())) return true; } else if (extension == "png") { // PNG format - if (stbi_write_png(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0], 0)) + if (stbi_write_png(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 0)) return true; } else if (extension == "jpg" || extension == "jpeg") { // JPG format - if (stbi_write_jpg(filename.c_str(), convertedSize.x, convertedSize.y, 4, &pixels[0], 90)) + if (stbi_write_jpg(filename.c_str(), convertedSize.x, convertedSize.y, 4, pixels.data(), 90)) return true; } } @@ -297,25 +297,25 @@ bool ImageLoader::saveImageToMemory(const std::string& format, std::vector(size)); - file.read(&buffer[0], static_cast(size)); + file.read(buffer.data(), static_cast(size)); } buffer.push_back('\0'); return true; @@ -105,7 +105,7 @@ namespace { buffer.resize(static_cast(size)); stream.seek(0); - sf::Int64 read = stream.read(&buffer[0], size); + sf::Int64 read = stream.read(buffer.data(), size); success = (read == size); } buffer.push_back('\0'); @@ -247,11 +247,11 @@ bool Shader::loadFromFile(const std::string& filename, Type type) // Compile the shader program if (type == Vertex) - return compile(&shader[0], nullptr, nullptr); + return compile(shader.data(), nullptr, nullptr); else if (type == Geometry) - return compile(nullptr, &shader[0], nullptr); + return compile(nullptr, shader.data(), nullptr); else - return compile(nullptr, nullptr, &shader[0]); + return compile(nullptr, nullptr, shader.data()); } @@ -275,7 +275,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st } // Compile the shader program - return compile(&vertexShader[0], nullptr, &fragmentShader[0]); + return compile(vertexShader.data(), nullptr, fragmentShader.data()); } @@ -307,7 +307,7 @@ bool Shader::loadFromFile(const std::string& vertexShaderFilename, const std::st } // Compile the shader program - return compile(&vertexShader[0], &geometryShader[0], &fragmentShader[0]); + return compile(vertexShader.data(), geometryShader.data(), fragmentShader.data()); } @@ -353,11 +353,11 @@ bool Shader::loadFromStream(InputStream& stream, Type type) // Compile the shader program if (type == Vertex) - return compile(&shader[0], nullptr, nullptr); + return compile(shader.data(), nullptr, nullptr); else if (type == Geometry) - return compile(nullptr, &shader[0], nullptr); + return compile(nullptr, shader.data(), nullptr); else - return compile(nullptr, nullptr, &shader[0]); + return compile(nullptr, nullptr, shader.data()); } @@ -381,7 +381,7 @@ bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& fragme } // Compile the shader program - return compile(&vertexShader[0], nullptr, &fragmentShader[0]); + return compile(vertexShader.data(), nullptr, fragmentShader.data()); } @@ -413,7 +413,7 @@ bool Shader::loadFromStream(InputStream& vertexShaderStream, InputStream& geomet } // Compile the shader program - return compile(&vertexShader[0], &geometryShader[0], &fragmentShader[0]); + return compile(vertexShader.data(), geometryShader.data(), fragmentShader.data()); } @@ -598,7 +598,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec2* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform2fv(binder.location, static_cast(length), &contiguous[0])); + glCheck(GLEXT_glUniform2fv(binder.location, static_cast(length), contiguous.data())); } @@ -609,7 +609,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec3* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform3fv(binder.location, static_cast(length), &contiguous[0])); + glCheck(GLEXT_glUniform3fv(binder.location, static_cast(length), contiguous.data())); } @@ -620,7 +620,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Vec4* vectorAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniform4fv(binder.location, static_cast(length), &contiguous[0])); + glCheck(GLEXT_glUniform4fv(binder.location, static_cast(length), contiguous.data())); } @@ -635,7 +635,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat3* matrixAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniformMatrix3fv(binder.location, static_cast(length), GL_FALSE, &contiguous[0])); + glCheck(GLEXT_glUniformMatrix3fv(binder.location, static_cast(length), GL_FALSE, contiguous.data())); } @@ -650,7 +650,7 @@ void Shader::setUniformArray(const std::string& name, const Glsl::Mat4* matrixAr UniformBinder binder(*this, name); if (binder.location != -1) - glCheck(GLEXT_glUniformMatrix4fv(binder.location, static_cast(length), GL_FALSE, &contiguous[0])); + glCheck(GLEXT_glUniformMatrix4fv(binder.location, static_cast(length), GL_FALSE, contiguous.data())); } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 28b9439bb..0f1282d80 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -346,7 +346,7 @@ Image Texture::copyToImage() const glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, frameBuffer)); glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); - glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); + glCheck(glReadPixels(0, 0, m_size.x, m_size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data())); glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, previousFrameBuffer)); @@ -358,7 +358,7 @@ Image Texture::copyToImage() const { // Texture is not padded nor flipped, we can use a direct copy glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0])); + glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data())); } else { @@ -367,11 +367,11 @@ Image Texture::copyToImage() const // All the pixels will first be copied to a temporary array std::vector allPixels(m_actualSize.x * m_actualSize.y * 4); glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0])); + glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data())); // Then we copy the useful pixels from the temporary array to the final one - const Uint8* src = &allPixels[0]; - Uint8* dst = &pixels[0]; + const Uint8* src = allPixels.data(); + Uint8* dst = pixels.data(); unsigned int srcPitch = m_actualSize.x * 4; unsigned int dstPitch = m_size.x * 4; @@ -394,7 +394,7 @@ Image Texture::copyToImage() const // Create the image Image image; - image.create(m_size.x, m_size.y, &pixels[0]); + image.create(m_size.x, m_size.y, pixels.data()); return image; } diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp index c5716951b..06aeb889d 100644 --- a/src/SFML/Graphics/VertexArray.cpp +++ b/src/SFML/Graphics/VertexArray.cpp @@ -144,7 +144,7 @@ FloatRect VertexArray::getBounds() const void VertexArray::draw(RenderTarget& target, RenderStates states) const { if (!m_vertices.empty()) - target.draw(&m_vertices[0], m_vertices.size(), m_primitiveType, states); + target.draw(m_vertices.data(), m_vertices.size(), m_primitiveType, states); } } // namespace sf diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index bdaf782a4..be8102262 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -82,7 +82,7 @@ void Packet::clear() //////////////////////////////////////////////////////////// const void* Packet::getData() const { - return !m_data.empty() ? &m_data[0] : nullptr; + return !m_data.empty() ? m_data.data() : nullptr; } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 3381ccb97..ba53fa5a8 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -328,10 +328,10 @@ Socket::Status TcpSocket::send(Packet& packet) // Copy the packet size and data into the block to send #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnull-dereference" // False positive. - std::memcpy(&blockToSend[0], &packetSize, sizeof(packetSize)); + std::memcpy(blockToSend.data(), &packetSize, sizeof(packetSize)); #pragma GCC diagnostic pop if (size > 0) - std::memcpy(&blockToSend[0] + sizeof(packetSize), data, size); + std::memcpy(blockToSend.data() + sizeof(packetSize), data, size); // These warnings are ignored here for portability, as even on Windows the // signature of `send` might change depending on whether Win32 or MinGW is @@ -342,7 +342,7 @@ Socket::Status TcpSocket::send(Packet& packet) #pragma GCC diagnostic ignored "-Wsign-conversion" // Send the data block std::size_t sent; - Status status = send(&blockToSend[0] + packet.m_sendPos, static_cast(blockToSend.size() - packet.m_sendPos), sent); + Status status = send(blockToSend.data() + packet.m_sendPos, static_cast(blockToSend.size() - packet.m_sendPos), sent); #pragma GCC diagnostic pop #pragma GCC diagnostic pop @@ -406,14 +406,14 @@ Socket::Status TcpSocket::receive(Packet& packet) if (received > 0) { m_pendingPacket.Data.resize(m_pendingPacket.Data.size() + received); - char* begin = &m_pendingPacket.Data[0] + m_pendingPacket.Data.size() - received; + char* begin = m_pendingPacket.Data.data() + m_pendingPacket.Data.size() - received; std::memcpy(begin, buffer, received); } } // We have received all the packet data: we can copy it to the user packet if (!m_pendingPacket.Data.empty()) - packet.onReceive(&m_pendingPacket.Data[0], m_pendingPacket.Data.size()); + packet.onReceive(m_pendingPacket.Data.data(), m_pendingPacket.Data.size()); // Clear the pending packet data m_pendingPacket = PendingPacket(); diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index c90462ccf..012f68779 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -192,12 +192,12 @@ Socket::Status UdpSocket::receive(Packet& packet, IpAddress& remoteAddress, unsi // Receive the datagram std::size_t received = 0; - Status status = receive(&m_buffer[0], m_buffer.size(), received, remoteAddress, remotePort); + Status status = receive(m_buffer.data(), m_buffer.size(), received, remoteAddress, remotePort); // If we received valid data, we can copy it to the user packet packet.clear(); if ((status == Done) && (received > 0)) - packet.onReceive(&m_buffer[0], received); + packet.onReceive(m_buffer.data(), received); return status; } diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index 28bd3c314..fa1c880c5 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -292,7 +292,7 @@ Joystick::Identification JoystickImpl::getIdentification() const //////////////////////////////////////////////////////////// JoystickState JoystickImpl::JoystickImpl::update() { - while (read(m_file, &m_buffer[0], m_length) == m_length) + while (read(m_file, m_buffer.data(), m_length) == m_length) { hid_data_t data = hid_start_parse(m_desc, 1 << hid_input, m_id); @@ -311,11 +311,11 @@ JoystickState JoystickImpl::JoystickImpl::update() if (usage == HUP_BUTTON) { - m_state.buttons[buttonIndex++] = hid_get_data(&m_buffer[0], &item); + m_state.buttons[buttonIndex++] = hid_get_data(m_buffer.data(), &item); } else if (usage == HUP_GENERIC_DESKTOP) { - int value = hid_get_data(&m_buffer[0], &item); + int value = hid_get_data(m_buffer.data(), &item); int axis = usageToAxis(usage); if (usage == HUG_HAT_SWITCH) diff --git a/src/SFML/Window/NetBSD/JoystickImpl.cpp b/src/SFML/Window/NetBSD/JoystickImpl.cpp index 574eb1106..894951e2a 100644 --- a/src/SFML/Window/NetBSD/JoystickImpl.cpp +++ b/src/SFML/Window/NetBSD/JoystickImpl.cpp @@ -297,7 +297,7 @@ Joystick::Identification JoystickImpl::getIdentification() const //////////////////////////////////////////////////////////// JoystickState JoystickImpl::JoystickImpl::update() { - while (read(m_file, &m_buffer[0], m_length) == m_length) + while (read(m_file, m_buffer.data(), m_length) == m_length) { hid_data_t data = hid_start_parse(m_desc, 1 << hid_input, m_id); @@ -316,11 +316,11 @@ JoystickState JoystickImpl::JoystickImpl::update() if (usage == HUP_BUTTON) { - m_state.buttons[buttonIndex++] = hid_get_data(&m_buffer[0], &item); + m_state.buttons[buttonIndex++] = hid_get_data(m_buffer.data(), &item); } else if (usage == HUP_GENERIC_DESKTOP) { - int value = hid_get_data(&m_buffer[0], &item); + int value = hid_get_data(m_buffer.data(), &item); int axis = usageToAxis(usage); if (usage == HUG_HAT_SWITCH) diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index 546940c00..5a81782b8 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -46,8 +46,8 @@ namespace CFIndex length = CFStringGetLength(cfString); std::vector str(length); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8); - CFStringGetCString(cfString, &str[0], maxSize, kCFStringEncodingUTF8); - return &str[0]; + CFStringGetCString(cfString, str.data(), maxSize, kCFStringEncodingUTF8); + return str.data(); } // Get HID device property key as a string diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index 5dec79f9c..80b2aad23 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -263,7 +263,7 @@ void SFContext::createContext(SFContext* shared, m_settings.sRgbCapable = true; // Create the pixel format. - NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:&attrs[0]]; + NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs.data()]; if (pixFmt == nil) { diff --git a/src/SFML/Window/Unix/ClipboardImpl.cpp b/src/SFML/Window/Unix/ClipboardImpl.cpp index fbb72f23a..6b92f781b 100644 --- a/src/SFML/Window/Unix/ClipboardImpl.cpp +++ b/src/SFML/Window/Unix/ClipboardImpl.cpp @@ -306,7 +306,7 @@ void ClipboardImpl::processEvent(XEvent& windowEvent) XA_ATOM, 32, PropModeReplace, - reinterpret_cast(&targets[0]), + reinterpret_cast(targets.data()), static_cast(targets.size()) ); diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp index 95cc6ff95..d708937ee 100644 --- a/src/SFML/Window/Unix/CursorImpl.cpp +++ b/src/SFML/Window/Unix/CursorImpl.cpp @@ -131,9 +131,9 @@ bool CursorImpl::loadFromPixelsMonochrome(const Uint8* pixels, Vector2u size, Ve } Pixmap maskPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display), - reinterpret_cast(&mask[0]), size.x, size.y); + reinterpret_cast(mask.data()), size.x, size.y); Pixmap dataPixmap = XCreateBitmapFromData(m_display, XDefaultRootWindow(m_display), - reinterpret_cast(&data[0]), size.x, size.y); + reinterpret_cast(data.data()), size.x, size.y); // Define the foreground color as white and the background as black. XColor fg, bg; diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index c401d1814..2a27649d2 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -726,7 +726,7 @@ void GlxContext::createContext(GlxContext* shared) } // Create the context - m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, &attributes[0]); + m_context = glXCreateContextAttribsARB(m_display, *config, toShare, true, attributes.data()); if (!m_context) { diff --git a/src/SFML/Window/Unix/VulkanImplX11.cpp b/src/SFML/Window/Unix/VulkanImplX11.cpp index ab1370a30..1bd5701f8 100644 --- a/src/SFML/Window/Unix/VulkanImplX11.cpp +++ b/src/SFML/Window/Unix/VulkanImplX11.cpp @@ -137,7 +137,7 @@ bool VulkanImplX11::isAvailable(bool requireGraphics) extensionProperties.resize(extensionCount); - wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, &extensionProperties[0]); + wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, extensionProperties.data()); // Check if the necessary extensions are available bool has_VK_KHR_surface = false; diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 68bd38c09..a026a4d69 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -131,7 +131,7 @@ namespace buffer[offset] = 0; // Remove the path to keep the executable name only - return basename(&buffer[0]); + return basename(buffer.data()); } // Default fallback name @@ -732,7 +732,7 @@ m_lastInputTime (0) std::string executableName = findExecutableName(); std::vector windowInstance(executableName.size() + 1, 0); std::copy(executableName.begin(), executableName.end(), windowInstance.begin()); - hint->res_name = &windowInstance[0]; + hint->res_name = windowInstance.data(); // The class name identifies a class of windows that // "are of the same type". We simply use the initial window name as @@ -740,7 +740,7 @@ m_lastInputTime (0) std::string ansiTitle = title.toAnsiString(); std::vector windowClass(ansiTitle.size() + 1, 0); std::copy(ansiTitle.begin(), ansiTitle.end(), windowClass.begin()); - hint->res_class = &windowClass[0]; + hint->res_class = windowClass.data(); XSetClassHint(m_display, m_window, hint); @@ -1051,7 +1051,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 } } } - m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(&maskPixels[0]), width, height, 1, 0, 1); + m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(maskPixels.data()), width, height, 1, 0, 1); // Send our new icon to the window through the WMHints XWMHints* hints = XAllocWMHints(); @@ -1064,7 +1064,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // ICCCM wants BGRA pixels: swap red and blue channels // ICCCM also wants the first 2 unsigned 32-bit values to be width and height std::vector icccmIconPixels(2 + width * height, 0); - unsigned long* ptr = &icccmIconPixels[0]; + unsigned long* ptr = icccmIconPixels.data(); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnull-dereference" // False positive. @@ -1088,7 +1088,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 XA_CARDINAL, 32, PropModeReplace, - reinterpret_cast(&icccmIconPixels[0]), + reinterpret_cast(icccmIconPixels.data()), static_cast(2 + width * height)); XFlush(m_display); @@ -1591,7 +1591,7 @@ void WindowImplX11::setProtocols() XA_ATOM, 32, PropModeReplace, - reinterpret_cast(&atoms[0]), + reinterpret_cast(atoms.data()), static_cast(atoms.size())); } else diff --git a/src/SFML/Window/Win32/VulkanImplWin32.cpp b/src/SFML/Window/Win32/VulkanImplWin32.cpp index 5f17933f8..082487264 100644 --- a/src/SFML/Window/Win32/VulkanImplWin32.cpp +++ b/src/SFML/Window/Win32/VulkanImplWin32.cpp @@ -139,7 +139,7 @@ bool VulkanImplWin32::isAvailable(bool requireGraphics) extensionProperties.resize(extensionCount); - wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, &extensionProperties[0]); + wrapper.vkEnumerateInstanceExtensionProperties(0, &extensionCount, extensionProperties.data()); // Check if the necessary extensions are available bool has_VK_KHR_surface = false; diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index b3b196016..2ce273236 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -664,7 +664,7 @@ void WglContext::createContext(WglContext* shared) } // Create the context - m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, &attributes[0]); + m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, attributes.data()); } else { diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index e030e5a28..15545a816 100755 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -376,7 +376,7 @@ void WindowImplWin32::setIcon(unsigned int width, unsigned int height, const Uin } // Create the icon from the pixel array - m_icon = CreateIcon(GetModuleHandleW(nullptr), static_cast(width), static_cast(height), 1, 32, nullptr, &iconPixels[0]); + m_icon = CreateIcon(GetModuleHandleW(nullptr), static_cast(width), static_cast(height), 1, 32, nullptr, iconPixels.data()); // Set it as both big and small icon of the window if (m_icon)