//C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete':
//  FileMappedVector(const FileMappedVector&) = delete;
//C++ TO C# CONVERTER TODO TASK: C# has no equivalent to ' = delete':
//  FileMappedVector& operator =(const FileMappedVector&) = delete;

        public void open(string path, FileMappedVectorOpenMode mode = FileMappedVectorOpenMode.OPEN_OR_CREATE, ulong prefixSize = 0)
        {
            Debug.Assert(!isOpened());

            const ulong initialCapacity = 10;

            boost::filesystem.path filePath = path;
            boost::filesystem.path bakPath  = path + ".bak";
            bool fileExists;

            if (boost::filesystem.exists(filePath))
            {
                if (boost::filesystem.exists(bakPath))
                {
                    boost::filesystem.remove(bakPath);
                }

                fileExists = true;
            }
            else if (boost::filesystem.exists(bakPath))
            {
                boost::filesystem.rename(bakPath, filePath);
                fileExists = true;
            }
            else
            {
                fileExists = false;
            }

            if (mode == FileMappedVectorOpenMode.OPEN)
            {
                open(path, new ulong(prefixSize));
            }
            else if (mode == FileMappedVectorOpenMode.CREATE)
            {
                create(path, new ulong(initialCapacity), new ulong(prefixSize), 0);
            }
            else if (mode == FileMappedVectorOpenMode.OPEN_OR_CREATE)
            {
                if (fileExists)
                {
                    open(path, new ulong(prefixSize));
                }
                else
                {
                    create(path, new ulong(initialCapacity), new ulong(prefixSize), 0);
                }
            }
            else
            {
                throw new System.Exception("FileMappedVector: Unsupported open mode: " + Convert.ToString((int)mode));
            }
        }
//C++ TO C# CONVERTER TODO TASK: The original C++ template specifier was replaced with a C# generic specifier, which may not produce the same behavior:
//ORIGINAL LINE: template<class F>
//C++ TO C# CONVERTER TODO TASK: 'rvalue references' have no equivalent in C#:
        private void atomicUpdate0 <F>(ulong newCapacity, ulong newPrefixSize, ulong newSuffixSize, F&& func)
        {
            if (m_file.path() != m_path)
            {
                throw new System.Exception("Vector is mapped to a .bak file due to earlier errors");
            }

            boost::filesystem.path bakPath = m_path + ".bak";
            boost::filesystem.path tmpPath = boost::filesystem.unique_path(m_path + ".tmp.%%%%-%%%%");

            if (boost::filesystem.exists(bakPath))
            {
                boost::filesystem.remove(bakPath);
            }

            Tools.ScopeExit tmpFileDeleter(() =>
            {
                boost::system.error_code ignore = new boost::system.error_code();
                boost::filesystem.remove(tmpPath, ignore);
            });

            // Copy file. It is slow but atomic operation
            FileMappedVector <T> tmpVector = new FileMappedVector <T>();

            tmpVector.create(tmpPath.string(), new ulong(newCapacity), new ulong(newPrefixSize), new ulong(newSuffixSize));
            func(tmpVector);
            tmpVector.flush();

            // Swap files
            std::error_code ec     = new std::error_code();
            std::error_code ignore = new std::error_code();

            m_file.rename(bakPath.string());
            tmpVector.rename(m_path, ec);
            if (ec != null)
            {
                // Try to restore and ignore errors
                m_file.rename(m_path, ignore);
                throw std::system_error(ec, "Failed to swap temporary and vector files");
            }

            m_path = bakPath.string();
            swap(tmpVector);
            tmpFileDeleter.cancel();

            // Remove .bak file and ignore errors
            tmpVector.close(ignore);
            boost::system.error_code boostError = new boost::system.error_code();
            boost::filesystem.remove(bakPath, boostError);
        }