Remove ambiguity in construction of prevector #14030

pull Empact wants to merge 1 commits into bitcoin:master from Empact:ambiguous-prevector-constructor changing 1 files +1 −1
  1. Empact commented at 10:00 AM on August 23, 2018: member

    The call with this default argument is redundant with prevector(size_type) on line 251.

  2. Remove default argument to prevector constructor to remove ambiguity
    The call with this default argument is redundant with prevector(size_type).
    497e90c02b
  3. fanquake added the label Refactoring on Aug 23, 2018
  4. Empact renamed this:
    Remove default argument to prevector constructor to remove ambiguity
    Remove ambiguity in construction of prevector
    on Aug 23, 2018
  5. Empact commented at 10:35 AM on August 23, 2018: member

    Note the effective implementation of resize(n) in this case is:

            change_capacity(n);
            _size += n;
            fill(item_ptr(0), n);
    
  6. AkioNak approved
  7. AkioNak commented at 10:57 AM on August 23, 2018: contributor

    utACK

  8. DrahtBot commented at 11:28 AM on August 23, 2018: member

    <!--e57a25ab6845829454e8d69fc972939a-->Note to reviewers: This pull request conflicts with the following ones:

    • #14028 (Explicitly initialize prevector _union by Empact)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  9. in src/prevector.h:255 in 497e90c02b
     251 | @@ -252,7 +252,7 @@ class prevector {
     252 |          resize(n);
     253 |      }
     254 |  
     255 | -    explicit prevector(size_type n, const T& val = T()) : _size(0) {
     256 | +    explicit prevector(size_type n, const T& val) : _size(0) {
    


    sipa commented at 4:26 PM on August 23, 2018:

    The explicit keyword is also redundant for constructions with >1 argument.


    Empact commented at 4:49 PM on August 23, 2018:

    theuni commented at 6:05 PM on August 23, 2018:

    Neat!

    It's not really relevant here, but I'll expand on @Empact's comment because it's something I didn't know, maybe others will benefit as well.

    Post c++11:

        using ScriptType = prevector<28, unsigned char>;
        ScriptType vec{1, 255};   // always works
        vec = ScriptType{1, 255}; // always works
        vec = {1, 255};           // only works if prevector's ctor is not explicit.
    

    caveat: the 3rd example above does not actually work because of prevector's templated iterator ctor, but that's unrelated.

  10. sipa commented at 4:26 PM on August 23, 2018: member

    utACK

  11. theuni commented at 6:11 PM on August 23, 2018: member

    utACK 497e90c02b96e8739e8faf3d43e41ba1ff0627b7.

    For reference, with c++11, std::vector's matching constructor also removed its default argument and dropped the explicit qualifier.

  12. laanwj merged this on Aug 27, 2018
  13. laanwj closed this on Aug 27, 2018

  14. laanwj referenced this in commit 4a1a2148f6 on Aug 27, 2018
  15. PastaPastaPasta referenced this in commit 50a08e7ad7 on Jun 27, 2021
  16. PastaPastaPasta referenced this in commit 5729b7b84a on Jun 28, 2021
  17. PastaPastaPasta referenced this in commit bd09fb3ae4 on Jun 29, 2021
  18. PastaPastaPasta referenced this in commit 1843687f45 on Jun 29, 2021
  19. PastaPastaPasta referenced this in commit 32dc57486c on Jun 29, 2021
  20. PastaPastaPasta referenced this in commit c0d7a261c4 on Jun 29, 2021
  21. PastaPastaPasta referenced this in commit de43330181 on Jun 29, 2021
  22. Munkybooty referenced this in commit 19d78e8757 on Jun 30, 2021
  23. Munkybooty referenced this in commit 1d6003de86 on Jul 1, 2021
  24. PastaPastaPasta referenced this in commit 5773399cc3 on Jul 1, 2021
  25. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me