Comments (3)
Hi Juan,
I would also suggest to use the std::size_t
type in place of the int
type in methods like
int numberOfXXX()
,... getXXX(int)
,void setXXX(..., int)
... removeXXX(int)
Some weeks ago, I prepared a specific branch in my fork
https://github.com/sguazt/fuzzylite/tree/patch/use-size_t
which however was based on a fork of your v5.x branch.
Currently I have no time for development, but maybe in the next months I can try to port the changes in the develop branch.
Let me know.
Cheers,
Marco
from fuzzylite.
Hi Marco,
thank you very much for your work! I will check if I can merge that into the develop
branch.
However, could you elaborate a bit on why should I use return types of std::size_t
instead of std::vector<T>::size_type
? I really liked int
because it is less verbose, but if this needs to be changed, then why not the std::vector<T>::size_type
?
Cheers,
Juan.
from fuzzylite.
Hi,
The reason to use std::size_t
in place of int
is to avoid possible conversion errors.
Most of the containers used inside fuzzylite
classes use an unsigned integral type to return the number of elements, while the int numberOfXXX()
methods use a signed integral type. This means that if the number of elements stored in the container is greater than std::numeric_limits<int>::max()
it is likely to run into an overflow problem.
Also note that std::size_t
is usually implemented as unsigned long
, so you got an additional problem in case sizeof(int) < sizeof(long)
.
Regarding your proposal to use std::vector<T>::size_type
, personally I don't like it since:
- You expose to the user of the classes the internal details of your implementation. If one day, for some reason, you decide to use a container other than
std::vector
you'll have to change the public signature of your APIs to match thenew_container::size_type
type. - As far as I know. the type
std::size_t
is really the standard and recommended way (in the C++ sense) to refer to types that represents a size (likewise,std::ptrdiff_t
is the standard type to use to represent differences and offsets). From the C++14 draft standard (sec. 18.2):- The type
size_t
is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object - The type
ptrdiff_t
is an implementation-defined signed integer type that can hold the difference of two subscripts in an array object
- The type
Obviously, this is my personal point of view
Cheers,
Marco
from fuzzylite.
Related Issues (20)
- AUR - fuzzylite compilation failed HOT 6
- Run tests on Windows
- Compiling errors under Ubuntu 22.04 HOT 6
- Missunderstanding of the obstacle avoidance example HOT 2
- Outdated Doxygen URL in README.md HOT 2
- Outdated guideline hyperlink in CONTRIBUTING.md HOT 8
- Build issue with glibc 2.34 HOT 4
- support for catch2 v3
- Can not open the source file "fl/Headers.h" HOT 2
- FL_VERSION left in fuzzylite.pc.in HOT 1
- test hardcodes path
- doxygen files in git
- fuzzylite stores build path in output binary HOT 5
- executable file without shebang
- unit test fails on i386 HOT 4
- Energia code for fuzzy speed controller on C language
- Releasing this under vcpkg HOT 3
- Segmentation fault when `fl::*` objects embedded in C++ class HOT 2
- Tests fail to compile with glibc >= 2.34 HOT 9
- TODO: Version 7.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fuzzylite.