Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [solved]An U++ equivalent of bzero ? (if not a sin) (Can I bzero a flat array of double, or should I use some container template instead?)
Re: An U++ equivalent of bzero ? (if not a sin) [message #52641 is a reply to message #52639] Sat, 02 November 2019 22:26 Go to previous messageGo to previous message
Klugier is currently offline  Klugier
Messages: 1099
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Frank,

For plain arrays you can use std::fill from standard library:
#include <iostream>

int main() {
        double array[10];
        std::fill(std::begin(array), std::end(array), 0.0);

        for (int i = 0; i < 10; ++i) {
                std::cout << array[i] << "\n";
        }

        return 0;
}


Alternatively, you could use std::array that have compilation time defined size:
#include <iostream>
#include <array>

int main() {
        std::array<double, 10> array;
        array.fill(0.0);

        for (auto d : array) {
                std::cout << d << "\n";
        }

        return 0;
}


I prefer to use std::fill for plain arrays, because it is probable solution and works outside U++, however it requires c++17 standard. However, if your app is designed to work with Upp framework than you can freely use Upp::Zero, which is easy to use (easier than std::fill).

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Sat, 02 November 2019 22:36]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [SOLVED] Empty values to the "EditInt" widget and the "int" basic type
Next Topic: Upp::Vector FindIndex by value of Object
Goto Forum:
  


Current Time: Tue May 13 20:51:40 CEST 2025

Total time taken to generate the page: 0.03142 seconds