https://github.com/b1f6c1c4/cpp-create-objects
How many ways to create object(s) in C++?
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.1%) to scientific vocabulary
Keywords
Repository
How many ways to create object(s) in C++?
Basic Info
Statistics
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
How many ways to create object(s) in C++?
Only heard of T a and new T()? You are not a REAL™ C++ programmer.
Checkout how many ways you can think of to create some objects.
Rules
- Write your snippet in
snippet/**/*.hpp:- We will
#include <stdlib.h>for you at the beginning. - It should have one (1) function definition named
create: - You may use auxilliary typedef, function, etc.
- You may NOT do anything irrelevent to the object creation.
- You MUST use
autowhenever possible. - The creation method should be universal - not just for our
stub.
- We will
- Checkout
main.cppand see what is considered valid.- Remember,
MAGIC_NUMBERis 114514.
- Remember,
- Two creation methods are considered identical if they:
- are lexically the same (adding comments); or
- are syntactically the same (adding parentheses); or
- are (trivially) semantically the same (
1+1v.s.2); or - are identical after preprocessor;
- only differ quantitatively (repeating something)
- Two methods are NEVER considered identical if they:
- call different constructors
- Dirty methods are allowed as long as they:
- are not identical to previous methods;
- are compilable by both g++ and clang++ on ubunut xenial;
- don't triggering any warnings (
-Wextra); - are not "evil" (
rm -rf /*)
- Additional rules for
single:- with template
typename T; - of signature
T (); - invoke the constructor of
Texactly once (1);- copy-constructor and move-constructor are NOT included
- return an instance of
T.
- with template
- Additional rules for
array:- with template
typename T; - of signature
void (check_t<T>), wherecheck_t<T> = void (*)(size_t, T (*)[3])); - invoke the constructor of
Texactly three (3) times- copy-constructor and move-constructor are NOT included
- treat the three values equally (i.e., construct them the same way)
- invoke the function pointer exactly once (1):
- the first parameter should be the
sizeofof the array - the second parameter should be the pointer to the created array
- the first parameter should be the
- with template
Example
snippet/single/named-default.hpp:
c++
template <typename T>
T create()
{
T a;
return a;
}
snippet/single/new-empty.hpp:
c++
template <typename T>
T create()
{
return *new T();
}
snippet/array/named-default.hpp:
c++
template <typename T>
void create(check_t check)
{
T a[3];
check(sizeof(a), &a);
}
License
We don't want you to think about legal consequence every time before creating an object. This project is proudly licensed as Creative Commons Zero v1.0 Universal
Owner
- Login: b1f6c1c4
- Kind: user
- Location: NJ, USA
- Company: Princeton University
- Repositories: 26
- Profile: https://github.com/b1f6c1c4
52BE D143 A92D BE96 2B83 092B 9BAC 0164 9600 1E70
GitHub Events
Total
Last Year
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| b1f6c1c4 | b****4@g****m | 15 |
| Jacob Zhong | c****e@q****m | 5 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 1
- Total pull requests: 2
- Average time to close issues: about 15 hours
- Average time to close pull requests: about 17 hours
- Total issue authors: 1
- Total pull request authors: 1
- Average comments per issue: 4.0
- Average comments per pull request: 0.5
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- cmpute (1)
Pull Request Authors
- cmpute (2)